Skip to content

Commit 28510cb

Browse files
committed
chore(fill): delete output dir after pytest-html sessionfinish runs
1 parent 8190086 commit 28510cb

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/pytest_plugins/filler/filler.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ def pytest_collection_modifyitems(
11631163
items.pop(i)
11641164

11651165

1166+
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
11661167
def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
11671168
"""
11681169
Perform session finish tasks.
@@ -1180,23 +1181,25 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
11801181
pre_alloc_groups_folder = fixture_output.pre_alloc_groups_folder_path
11811182
pre_alloc_groups_folder.mkdir(parents=True, exist_ok=True)
11821183
session.config.pre_alloc_groups.to_folder(pre_alloc_groups_folder)
1183-
return
11841184

11851185
if xdist.is_xdist_worker(session):
1186+
yield
11861187
return
11871188

11881189
if fixture_output.is_stdout or is_help_or_collectonly_mode(session.config):
1190+
yield
11891191
return
11901192

11911193
# Remove any lock files that may have been created.
11921194
for file in fixture_output.directory.rglob("*.lock"):
11931195
file.unlink()
11941196

1195-
# Generate index file for all produced fixtures.
1197+
yield # ensure that the following runs after pytest-html's pytest_sessionfinish hook
1198+
1199+
# Generate index file for all produced fixtures, respectively remove output dir.
11961200
if session.config.getoption("generate_index") and not session.config.getoption(
11971201
"generate_pre_alloc_groups"
11981202
):
1199-
# only create fixtures dir if at least one test was filled
12001203
amount_of_collected_tests = getattr(session, "testscollected", 0)
12011204
if amount_of_collected_tests > 0:
12021205
generate_fixtures_index(
@@ -1206,17 +1209,7 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
12061209
disable_infer_format=False,
12071210
)
12081211
else:
1209-
# nuke the fixtures dir, but only if:
1210-
# * html output is disabled
1211-
# and
1212-
# * no tests were filled
1213-
html_output_is_enabled = getattr(session.config.option, "htmlpath", None)
1214-
if not html_output_is_enabled:
1215-
# determine chosen fixtures output folder
1216-
fixture_output_obj: FixtureOutput = FixtureOutput.from_config(session.config)
1217-
fixture_output_folder: Path = fixture_output_obj.output_path
1218-
# and delete it
1219-
shutil.rmtree(fixture_output_folder)
1212+
shutil.rmtree(fixture_output.output_path)
12201213

12211214
# Create tarball of the output directory if the output is a tarball.
12221215
fixture_output.create_tarball()

0 commit comments

Comments
 (0)