Skip to content

Commit

Permalink
pytest: Set testpaths to fix test collection
Browse files Browse the repository at this point in the history
pytest 8 had breaking changes in test collection, which prevented the
main test suite from being picked up in combination with our
`sourcetests_collection_hook`.
  • Loading branch information
juergbi committed Jul 26, 2024
1 parent 8df8873 commit 52b7212
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ parentdir_prefix = BuildStream-

[tool:pytest]
addopts = --verbose --basetemp ./tmp --durations=20 --timeout=1800
testpaths = tests
norecursedirs = src tests/integration/project tests/plugins/loading tests/plugins/sample-plugins integration-cache tmp __pycache__ .eggs
python_files = tests/*/*.py
env =
Expand Down
19 changes: 3 additions & 16 deletions src/buildstream/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,10 @@ def sourcetests_collection_hook(session):
"""

def should_collect_tests(config):
args = config.args
rootdir = config.rootdir
# When no args are supplied, pytest defaults the arg list to
# just include the session's root_dir. We want to collect
# When no args are supplied, pytest defaults the arg list to the
# value of the `testpaths` configuration option. We want to collect
# tests as part of the default collection
if args == [str(rootdir)]:
return True

# If specific tests are passed, don't collect
# everything. Pytest will handle this correctly without
# modification.
if len(args) > 1 or rootdir not in args:
return False

# If in doubt, collect them, this will be an easier bug to
# spot and is less likely to result in bug not being found.
return True
return config.args_source != pytest.Config.ArgsSource.ARGS

from . import _sourcetests

Expand Down

0 comments on commit 52b7212

Please sign in to comment.