Skip to content

Commit 8190086

Browse files
committed
nuke fixtures dir when html is disabled and no tests were filled
1 parent 75f51bc commit 8190086

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/pytest_plugins/filler/filler.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import configparser
1010
import datetime
1111
import os
12+
import shutil
1213
import warnings
1314
from enum import Enum
1415
from pathlib import Path
@@ -1195,9 +1196,27 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
11951196
if session.config.getoption("generate_index") and not session.config.getoption(
11961197
"generate_pre_alloc_groups"
11971198
):
1198-
generate_fixtures_index(
1199-
fixture_output.directory, quiet_mode=True, force_flag=False, disable_infer_format=False
1200-
)
1199+
# only create fixtures dir if at least one test was filled
1200+
amount_of_collected_tests = getattr(session, "testscollected", 0)
1201+
if amount_of_collected_tests > 0:
1202+
generate_fixtures_index(
1203+
fixture_output.directory,
1204+
quiet_mode=True,
1205+
force_flag=False,
1206+
disable_infer_format=False,
1207+
)
1208+
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)
12011220

12021221
# Create tarball of the output directory if the output is a tarball.
12031222
fixture_output.create_tarball()

0 commit comments

Comments
 (0)