Skip to content

Commit

Permalink
- added get_function, to parse out the test function name out of a te…
Browse files Browse the repository at this point in the history
…st node id;

- added missing tests;
  • Loading branch information
jaltmayerpizzorno committed Jun 15, 2024
1 parent 51691ab commit a218a74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/pytest_cleanslate/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,15 @@ def get_module(testid: str) -> str:
return testid.split('::')[0]


def is_module(testid: str) -> bool:
def _is_module(testid: str) -> bool:
return '::' not in testid


def get_function(testid: str) -> str:
if '::' in testid:
return testid.split('::')[1].split('[')[0]


def run_pytest(tests_path: Path, pytest_args=(), *,
modules: T.List[Path] = None, tests: T.List[str] = None, trace: bool = False) -> dict:
import tempfile
Expand Down Expand Up @@ -261,7 +266,7 @@ def reduce(*, tests_path: Path, results: Results = None, pytest_args: T.List[str
'error': 'No tests failed',
}

failed_is_module = is_module(failed_id)
failed_is_module = _is_module(failed_id)
if failed_is_module:
if trace: print()
print(f"Module \"{failed_id}\"'s collection failed; trying it by itself...", flush=True)
Expand Down
19 changes: 13 additions & 6 deletions tests/test_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@

import pytest_cleanslate.reduce as reduce

from pytest_cleanslate.reduce import MODULE_LIST_ARG, TEST_LIST_ARG, RESULTS_ARG, Results
from pytest_cleanslate.reduce import MODULE_LIST_ARG, TEST_LIST_ARG, RESULTS_ARG, Results, \
get_module, get_function


def get_test_module(testid):
return testid.split('::')[0]
def test_get_module():
assert 'test.py' == get_module('test.py')
assert 'test.py' == get_module('test.py::test_foo')
assert 'test.py' == get_module('test.py::test_foo[1]')

def test_get_function():
assert None == get_function('test.py')
assert 'test_foo' == get_function('test.py::test_foo')
assert 'test_foo' == get_function('test.py::test_foo[1]')

def test_run_pytest_collect_failure(tests_dir):
test1 = seq2p(tests_dir, 1)
Expand Down Expand Up @@ -148,7 +155,7 @@ def test_reduce(tests_dir, pollute_in_collect, fail_collect, r):
reduction = r(tests_path=tests_dir, trace=True)

assert reduction['failed'] == failing
assert reduction['modules'] == [get_test_module(polluter)]
assert reduction['modules'] == [get_module(polluter)]
assert reduction['tests'] == [] if pollute_in_collect else [polluter]


Expand Down Expand Up @@ -180,7 +187,7 @@ def test_nothing():
reduction = r(tests_path=tests_dir, trace=True)

assert reduction['failed'] == failing
assert reduction['modules'] == [get_test_module(polluter)]
assert reduction['modules'] == [get_module(polluter)]
assert reduction['tests'] == []


Expand All @@ -196,7 +203,7 @@ def test_reduce_pytest_args(tests_dir, pollute_in_collect, fail_collect, r):
reduction = r(tests_path=tests_dir, trace=True, pytest_args=['--noconftest'])

assert reduction['failed'] == failing
assert reduction['modules'] == [get_test_module(polluter)]
assert reduction['modules'] == [get_module(polluter)]
assert reduction['tests'] == [] if pollute_in_collect else [polluter]


Expand Down

0 comments on commit a218a74

Please sign in to comment.