diff --git a/conftest.py b/conftest.py new file mode 100644 index 00000000..ffd2d059 --- /dev/null +++ b/conftest.py @@ -0,0 +1,44 @@ +def pytest_addoption(parser): + parser.addoption( + "--force-log-cli", + action="store_true", + help="Force enable log_cli even when xdist is active", + ) + + +def pytest_configure(config): + # Detect if xdist (parallel execution) is active + xdist_active = hasattr(config, "workerinput") or config.pluginmanager.hasplugin( + "xdist" + ) + + +def pytest_addoption(parser): + parser.addoption( + "--force-log-cli", + action="store_true", + help="Force enable log_cli even when xdist is active", + ) + + +def pytest_configure(config): + # Detect if xdist (parallel execution) is active + xdist_active = hasattr(config, "workerinput") or config.pluginmanager.hasplugin( + "xdist" + ) + + if not xdist_active or config.getoption("--force-log-cli"): + # Normal run (no xdist): enable live logs + config.option.log_cli = True + config.option.log_cli_level = "INFO" + else: + # xdist active: disable live logs so we get the 'dots' progress + config.option.log_cli = False + + if not xdist_active or config.getoption("--force-log-cli"): + # Normal run (no xdist): enable live logs + config.option.log_cli = True + config.option.log_cli_level = "INFO" + else: + # xdist active: disable live logs so we get the 'dots' progress + config.option.log_cli = False diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..b2053773 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +log_cli_level = INFO +addopts = -ra diff --git a/test_sample.py b/test_sample.py new file mode 100644 index 00000000..fa78235f --- /dev/null +++ b/test_sample.py @@ -0,0 +1,11 @@ +import time + + +def test_example_1(): + time.sleep(0.5) + assert 1 == 1 + + +def test_example_2(): + time.sleep(0.5) + assert 2 == 2