Skip to content

Commit acf1bd8

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

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/pytest_plugins/filler/filler.py

Lines changed: 18 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,23 @@ 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+
shutil.rmtree("fixtures")
12011216

12021217
# Create tarball of the output directory if the output is a tarball.
12031218
fixture_output.create_tarball()

0 commit comments

Comments
 (0)