From 1d6cb53ac9c031d244a30d7aa68b38d85d8766b0 Mon Sep 17 00:00:00 2001 From: Alex Mazzeo Date: Thu, 16 Oct 2025 15:27:27 -0700 Subject: [PATCH 1/5] use some customazation to try to output to GHA better --- tests/conftest.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0ee203fb6..3b3cb659a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -41,11 +41,46 @@ from temporalio.testing import WorkflowEnvironment from tests.helpers.worker import ExternalPythonWorker, ExternalWorker +_IN_GHA = os.getenv("GITHUB_ACTIONS", "").lower() == "true" +_gha_current_file = None + +def pytest_configure(config): + if not _IN_GHA: + return + tr = config.pluginmanager.getplugin("terminalreporter") + if tr: + tr.showfspath = False + # if hasattr(tr, "write_fspath_result"): + # tr.write_fspath_result = lambda *a, **k: None + + +@pytest.hookimpl(hookwrapper=True) def pytest_runtest_setup(item): - """Print a newline so that custom printed output starts on new line.""" - if item.config.getoption("-s"): + """Print a newline so that custom printed output starts on new line. + In GHA, group test output together. + """ + global _gha_current_file + + if not _IN_GHA and item.config.getoption("-s"): print() + elif _IN_GHA: + file, _lineno, _testname = item.location + if file != _gha_current_file: + print() + print(f"::notice title=pytest file::{file}", flush=True) + _gha_current_file = file + + print(f"::group::{item.nodeid}", flush=True) + yield + if _IN_GHA: + print("::endgroup::", flush=True) + + +def pytest_report_teststatus(report, config): + """In GHA, suppress progress and allow grouping to format test output""" + if _IN_GHA: + return report.outcome, "", report.outcome.upper() def pytest_addoption(parser): From 9237476478e830b1c96200d636b198dafd8f9e4d Mon Sep 17 00:00:00 2001 From: Alex Mazzeo Date: Thu, 16 Oct 2025 15:59:56 -0700 Subject: [PATCH 2/5] remove configuration that didn't help. switch to runtest_protocol --- tests/conftest.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3b3cb659a..ef8fcea66 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,18 +45,8 @@ _gha_current_file = None -def pytest_configure(config): - if not _IN_GHA: - return - tr = config.pluginmanager.getplugin("terminalreporter") - if tr: - tr.showfspath = False - # if hasattr(tr, "write_fspath_result"): - # tr.write_fspath_result = lambda *a, **k: None - - -@pytest.hookimpl(hookwrapper=True) -def pytest_runtest_setup(item): +@pytest.hookimpl(hookwrapper=True, tryfirst=True) +def pytest_runtest_protocol(item): """Print a newline so that custom printed output starts on new line. In GHA, group test output together. """ @@ -72,10 +62,14 @@ def pytest_runtest_setup(item): _gha_current_file = file print(f"::group::{item.nodeid}", flush=True) - yield + + outcome = yield + if _IN_GHA: print("::endgroup::", flush=True) + return outcome + def pytest_report_teststatus(report, config): """In GHA, suppress progress and allow grouping to format test output""" From 08b12c55a6dc0e0c170d9a391df72794e8edba5d Mon Sep 17 00:00:00 2001 From: Alex Mazzeo Date: Thu, 16 Oct 2025 16:44:53 -0700 Subject: [PATCH 3/5] remove notices. try out some ansi colors --- tests/conftest.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ef8fcea66..de8312f17 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,6 @@ import asyncio +from contextlib import redirect_stderr, redirect_stdout +import io import os import sys from typing import AsyncGenerator @@ -54,16 +56,30 @@ def pytest_runtest_protocol(item): if not _IN_GHA and item.config.getoption("-s"): print() + outcome = yield elif _IN_GHA: file, _lineno, _testname = item.location if file != _gha_current_file: print() - print(f"::notice title=pytest file::{file}", flush=True) + print(f"\033[1;94mTesting {file}\033[0m", flush=True) _gha_current_file = file - print(f"::group::{item.nodeid}", flush=True) + test_output_buf = io.StringIO() + with redirect_stdout(test_output_buf): + with redirect_stderr(test_output_buf): + outcome = yield - outcome = yield + if outcome.get_result(): + print(f"::group::\033[1;92m{item.nodeid}\033[0m", flush=True) + else: + print(f"::group::\033[1;91m{item.nodeid}\033[0m", flush=True) + + output = test_output_buf.getvalue() + if len(output) > 0: + print(output) + + else: + outcome = yield if _IN_GHA: print("::endgroup::", flush=True) From 4daa14c8c00e20773b886459a64c777fdad70a9d Mon Sep 17 00:00:00 2001 From: Alex Mazzeo Date: Thu, 16 Oct 2025 16:50:06 -0700 Subject: [PATCH 4/5] run formatter --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index de8312f17..b5878ca57 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,8 @@ import asyncio -from contextlib import redirect_stderr, redirect_stdout import io import os import sys +from contextlib import redirect_stderr, redirect_stdout from typing import AsyncGenerator import pytest From e40ab269941e57ad09e5b191acfd4334716d94b6 Mon Sep 17 00:00:00 2001 From: Alex Mazzeo Date: Thu, 16 Oct 2025 16:58:59 -0700 Subject: [PATCH 5/5] try to prevent grouping breaking --- tests/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index b5878ca57..4267c4f5b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -47,6 +47,16 @@ _gha_current_file = None +def pytest_configure(config): + if not _IN_GHA: + return + tr = config.pluginmanager.getplugin("terminalreporter") + if tr: + tr.showfspath = False + if hasattr(tr, "write_fspath_result"): + tr.write_fspath_result = lambda *a, **k: None + + @pytest.hookimpl(hookwrapper=True, tryfirst=True) def pytest_runtest_protocol(item): """Print a newline so that custom printed output starts on new line.