mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
pytest: Pass result to fixtures and keep directories of failed tests
@Reported-by: Rusty Russell <@rustyrussell> @Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
parent
6627da5eb5
commit
b55d03cb30
2 changed files with 25 additions and 2 deletions
18
tests/conftest.py
Normal file
18
tests/conftest.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
# This function is based upon the example of how to
|
||||||
|
# "[make] test result information available in fixtures" at:
|
||||||
|
# https://pytest.org/latest/example/simple.html#making-test-result-information-available-in-fixtures
|
||||||
|
# and:
|
||||||
|
# https://github.com/pytest-dev/pytest/issues/288
|
||||||
|
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||||
|
def pytest_runtest_makereport(item, call):
|
||||||
|
# execute all other hooks to obtain the report object
|
||||||
|
outcome = yield
|
||||||
|
rep = outcome.get_result()
|
||||||
|
|
||||||
|
# set a report attribute for each phase of a call, which can
|
||||||
|
# be "setup", "call", "teardown"
|
||||||
|
|
||||||
|
setattr(item, "rep_" + rep.when, rep)
|
|
@ -35,7 +35,7 @@ def test_base_dir():
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def directory(test_base_dir, test_name):
|
def directory(request, test_base_dir, test_name):
|
||||||
"""Return a per-test specific directory.
|
"""Return a per-test specific directory.
|
||||||
|
|
||||||
This makes a unique test-directory even if a test is rerun multiple times.
|
This makes a unique test-directory even if a test is rerun multiple times.
|
||||||
|
@ -48,7 +48,12 @@ def directory(test_base_dir, test_name):
|
||||||
|
|
||||||
yield directory
|
yield directory
|
||||||
|
|
||||||
shutil.rmtree(directory)
|
# This uses the status set in conftest.pytest_runtest_makereport to
|
||||||
|
# determine whether we succeeded or failed.
|
||||||
|
if request.node.rep_call.outcome == 'passed':
|
||||||
|
shutil.rmtree(directory)
|
||||||
|
else:
|
||||||
|
logging.debug("Test execution failed, leaving the test directory {} intact.".format(directory))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
Loading…
Add table
Reference in a new issue