|
9 | 9 | import configparser
|
10 | 10 | import datetime
|
11 | 11 | import os
|
| 12 | +import shutil |
12 | 13 | import warnings
|
13 | 14 | from enum import Enum
|
14 | 15 | from pathlib import Path
|
@@ -1195,9 +1196,27 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int):
|
1195 | 1196 | if session.config.getoption("generate_index") and not session.config.getoption(
|
1196 | 1197 | "generate_pre_alloc_groups"
|
1197 | 1198 | ):
|
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) |
1201 | 1220 |
|
1202 | 1221 | # Create tarball of the output directory if the output is a tarball.
|
1203 | 1222 | fixture_output.create_tarball()
|
0 commit comments