Created
May 11, 2021 17:15
-
-
Save stas00/d879df7da231c1e5082a0ea1668a1007 to your computer and use it in GitHub Desktop.
pytest start/stop tracer - when needing to figure out which tests didn't finish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# conftest.py | |
# to run: | |
# TRACE_START_STOP=1 pytest tests/test_trainer.py | |
import pytest | |
import os | |
trace = os.environ.get('TRACE_START_STOP', "") | |
@pytest.hookimpl(tryfirst=True, hookwrapper=True) | |
def pytest_runtest_makereport(item, call): | |
outcome = yield | |
res = outcome.get_result() | |
file_name, _, test_name = res.location | |
test = f"{file_name} {test_name}" | |
if res.when == "setup" and res.passed: | |
if len(trace): | |
print(f"\nTRACE {test} start") | |
elif res.when == "call" and not res.passed: | |
pass | |
elif res.when == "teardown": | |
if len(trace): | |
print(f"\nTRACE {test} stop") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment