Skip to content

Commit

Permalink
Prefixes will be respected for discovery using AST tree; (#117)
Browse files Browse the repository at this point in the history
* Prefixes will be respected for discovery using AST tree;

Continuation of
#116

* Ruff

* Fixed pytest ini to include default test discovery patterns
  • Loading branch information
gleb-sevruk authored Feb 8, 2024
1 parent d69fdda commit 44d1dbf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .pycrunch-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ engine:
change-detection-root: .
# requires restart
enable-web-ui: true
module-prefixes: spec
function-prefixes: should must
env:
DJANGO_SETTINGS_MODULE: somedjangoapp.settings.local
pinned-tests:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ engine:

# Enable web UI (Default - `false`)
enable-web-ui: true

# Customize pytest.ini [spec_file.py -> def should_be_true()]
# python_files = test_*.py tests_*.py spec*.py moduletest*.py
module-prefixes: test spec moduletest
# python_functions = *_test should* must*
function-prefixes: should must

# Environment variables to forward to pytest executors
env:
Expand Down
6 changes: 5 additions & 1 deletion pycrunch/discovery/ast_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,14 @@ def is_module_with_tests(self, module_name):
return module_short_name.startswith((
'test_',
'tests_',
*self.configuration.module_prefixes,
)) or module_short_name.endswith(('_test', 'tests', '_tests'))

def looks_like_test_name(self, v):
return v.startswith('test_') or v.endswith('_test')
return any(
v.startswith(prefix)
for prefix in ['test_', *self.configuration.function_prefixes]
) or v.endswith('_test')

def looks_like_test_class(self, name: str) -> bool:
return name.startswith('Test') or name.endswith('Test')
Expand Down
10 changes: 10 additions & 0 deletions pycrunch_tests/tests_ast_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def test_double_inheritance():
assert 'DoublyInheritedScenario::test_1' in test_names


def test_custom_module_prefix():
configuration = Configuration()
configuration.module_prefixes = 'spec'
configuration.function_prefixes = 'should'
actual = run_dogfood_discovery(config=configuration)
test_names = list(map(lambda _: _.name, actual.tests))

assert 'should_regular_2' in test_names


def test_only_methods_are_discovered_not_variables():
actual = run_dogfood_discovery()
test_names = list(map(lambda _: _.name, actual.tests))
Expand Down
4 changes: 3 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[pytest]
python_files = test_*.py tests_*.py
python_files = test_*.py tests_*.py spec*.py *_test.py
python_functions = test_* *_test should_*

# This tests should be run separately, not inside unit testing suite
norecursedirs = integration_tests/*
# exclude_from_default_run - This tests are failing on purpose.
Expand Down

0 comments on commit 44d1dbf

Please sign in to comment.