Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefixes will be respected for discovery using AST tree; #117

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading