Skip to content

Commit 6e1dd88

Browse files
- small tweaks;
1 parent a218a74 commit 6e1dd88

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/pytest_cleanslate/reduce.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ def fails(module_set: T.List[str]):
253253
return _bisect_items(modules, failing_module, fails, bar=bar)
254254

255255

256-
def reduce(*, tests_path: Path, results: Results = None, pytest_args: T.List[str] = (), trace: bool = False, **args) -> dict:
256+
def reduce(*, tests_path: Path, results: Results = None, pytest_args: T.List[str] = (),
257+
trace: bool = False, **args) -> dict:
257258
if not results:
258259
print("Running tests...", flush=True)
259260
results = run_pytest(tests_path, (*pytest_args, '-x'), trace=trace)
@@ -292,9 +293,12 @@ def reduce(*, tests_path: Path, results: Results = None, pytest_args: T.List[str
292293
modules = _reduce_modules(tests_path, tests, failed_id, results.get_modules(), failed_module,
293294
trace=trace, pytest_args=pytest_args)
294295

295-
if trace: print()
296-
tests = _reduce_tests(tests_path, tests, failed_id, [*modules, failed_module],
297-
trace=trace, pytest_args=pytest_args)
296+
if not failed_is_module:
297+
if trace: print()
298+
tests = _reduce_tests(tests_path, tests, failed_id, [*modules, failed_module],
299+
trace=trace, pytest_args=pytest_args)
300+
301+
# TODO if tests != [], see if it's enough to disable just them
298302

299303
if trace: print()
300304
print("Reduced failure set:")

tests/test_reduce.py

+26-18
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ def test_get_module():
1818
assert 'test.py' == get_module('test.py::test_foo')
1919
assert 'test.py' == get_module('test.py::test_foo[1]')
2020

21+
2122
def test_get_function():
2223
assert None == get_function('test.py')
2324
assert 'test_foo' == get_function('test.py::test_foo')
2425
assert 'test_foo' == get_function('test.py::test_foo[1]')
2526

27+
2628
def test_run_pytest_collect_failure(tests_dir):
2729
test1 = seq2p(tests_dir, 1)
2830
test1.write_text(dedent("""\
@@ -148,15 +150,37 @@ def test_reduce_test_fails_by_itself(tests_dir, r):
148150
@pytest.mark.parametrize("pollute_in_collect, fail_collect", [[False, False], [True, False], [True, True]])
149151
@pytest.mark.parametrize("r", [reduce.reduce, cli_reduce])
150152
def test_reduce(tests_dir, pollute_in_collect, fail_collect, r):
151-
failing, polluter, tests = make_polluted_suite(tests_dir, fail_collect=fail_collect, pollute_in_collect=pollute_in_collect)
153+
failing, polluter, tests = make_polluted_suite(tests_dir, fail_collect=fail_collect,
154+
pollute_in_collect=pollute_in_collect)
152155

153156
reduction_file = tests_dir.parent / "reduction.json"
154157

155158
reduction = r(tests_path=tests_dir, trace=True)
156159

157160
assert reduction['failed'] == failing
158161
assert reduction['modules'] == [get_module(polluter)]
159-
assert reduction['tests'] == [] if pollute_in_collect else [polluter]
162+
# this would be more precise... is it the test or the module?
163+
# assert reduction['modules'] == ([get_module(polluter)] if pollute_in_collect else [])
164+
assert reduction['tests'] == ([] if pollute_in_collect else [polluter])
165+
166+
167+
@pytest.mark.parametrize("pollute_in_collect, fail_collect", [[False, False], [True, False], [True, True]])
168+
@pytest.mark.parametrize("r", [reduce.reduce, cli_reduce])
169+
def test_reduce_pytest_args(tests_dir, pollute_in_collect, fail_collect, r):
170+
failing, polluter, tests = make_polluted_suite(tests_dir, fail_collect=fail_collect,
171+
pollute_in_collect=pollute_in_collect)
172+
173+
(tests_dir / "conftest.py").write_text(dedent("""\
174+
if read, this breaks everything
175+
"""))
176+
177+
reduction = r(tests_path=tests_dir, trace=True, pytest_args=['--noconftest'])
178+
179+
assert reduction['failed'] == failing
180+
assert reduction['modules'] == [get_module(polluter)]
181+
# this would be more precise... is it the test or the module?
182+
# assert reduction['modules'] == ([get_module(polluter)] if pollute_in_collect else [])
183+
assert reduction['tests'] == ([] if pollute_in_collect else [polluter])
160184

161185

162186
@pytest.mark.parametrize("r", [reduce.reduce, cli_reduce])
@@ -191,22 +215,6 @@ def test_nothing():
191215
assert reduction['tests'] == []
192216

193217

194-
@pytest.mark.parametrize("pollute_in_collect, fail_collect", [[False, False], [True, False], [True, True]])
195-
@pytest.mark.parametrize("r", [reduce.reduce, cli_reduce])
196-
def test_reduce_pytest_args(tests_dir, pollute_in_collect, fail_collect, r):
197-
failing, polluter, tests = make_polluted_suite(tests_dir, fail_collect=fail_collect, pollute_in_collect=pollute_in_collect)
198-
199-
(tests_dir / "conftest.py").write_text(dedent("""\
200-
if read, this breaks everything
201-
"""))
202-
203-
reduction = r(tests_path=tests_dir, trace=True, pytest_args=['--noconftest'])
204-
205-
assert reduction['failed'] == failing
206-
assert reduction['modules'] == [get_module(polluter)]
207-
assert reduction['tests'] == [] if pollute_in_collect else [polluter]
208-
209-
210218
@pytest.mark.parametrize("r", [reduce.reduce, cli_reduce])
211219
def test_reduce_polluter_test_in_single_module(tests_dir, r):
212220
test = seq2p(tests_dir, 0)

0 commit comments

Comments
 (0)