Browse Source

fix(ci): Fix pytest annotations not working (#31500)

There were two problems, the plugin detection for `pytest_rerunfailures`
was not working and pytest was swallowing the errors.

The other problem seems to be, for whatever reason, the GH annotation
log was also being swallowed up (it was being printed to stderr).
Printing it to stdout seems to work?
Billy Vong 3 years ago
parent
commit
4bafe67e7a
1 changed files with 8 additions and 12 deletions
  1. 8 12
      conftest.py

+ 8 - 12
conftest.py

@@ -41,16 +41,14 @@ def pytest_runtest_makereport(item, call):
     if os.environ.get("GITHUB_ACTIONS") != "true":
         return
 
-    try:
-        # If we have the pytest_rerunfailures plugin,
-        # and there are still retries to be run,
-        # then do not return the error
+    # If we have the pytest_rerunfailures plugin,
+    # and there are still retries to be run,
+    # then do not return the error
+    if hasattr(item, "execution_count"):
         import pytest_rerunfailures
 
         if item.execution_count <= pytest_rerunfailures.get_reruns_count(item):
             return
-    except ImportError:
-        pass
 
     if report.when == "call" and report.failed:
         # collect information to be annotated
@@ -70,8 +68,9 @@ def pytest_runtest_makereport(item, call):
             if not rel_path.startswith(".."):
                 filesystempath = rel_path
 
-        # 0-index to 1-index
-        lineno += 1
+        if lineno is not None:
+            # 0-index to 1-index
+            lineno += 1
 
         # get the name of the current failed test, with parametrize info
         longrepr = report.head_line or item.name
@@ -80,13 +79,10 @@ def pytest_runtest_makereport(item, call):
         try:
             longrepr += "\n\n" + report.longrepr.reprcrash.message
             lineno = report.longrepr.reprcrash.lineno
-
         except AttributeError:
             pass
 
-        print(  # noqa: B314
-            _error_workflow_command(filesystempath, lineno, longrepr), file=sys.stderr
-        )
+        print(_error_workflow_command(filesystempath, lineno, longrepr))  # noqa: B314
 
 
 def _error_workflow_command(filesystempath, lineno, longrepr):