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

AUTO cases cannot be used from test files with non-test prefix, such as bench_*.py. Even if the latter are correct test files according to python_files. #326

Open
smarie opened this issue Jan 13, 2024 · 2 comments

Comments

@smarie
Copy link
Owner

smarie commented Jan 13, 2024

@mroeschke found this following #320

pytest introduced (in version 3 I guess) a python_files configuration option allowing users to change the naming patterns pytest is using to collect tests. (https://docs.pytest.org/en/stable/reference/reference.html#confval-python_files)

in #320 we became stricter on allowing AUTO cases to execute only on "valid test files" but we do not take into account the python_files glob patterns for this. Besides, our current definition of AUTO cases naming only holds for tests named test_*, and therefore will fail even for tests named *_test.py (which are considered valid by default in pytest).

See also https://docs.pytest.org/en/7.1.x/example/pythoncollection.html#changing-naming-conventions

  • We should probably try to leverage one of pytest internal functions to check if a file is a test file. That would ensure that the config options are used correctly and exactly the same way than inside pytest.
  • concerning the AUTO cases naming pattern, the above makes it hard to be "smart". The only thing I can think of (but it is ugly), would be to repeat the information explicitly to define a mapping. So
[pytest]
python_files =
    test_*.py
    check_*.py
    example_*.py

[pytest-cases]
auto_cases_files =
    test_*.py -> cases_*.py
    check_*.py -> cases_*_check.py
    example_*.py -> example_*_cases.py

The convention would be to have <source_pattern> -> <dest_pattern>, and it would be restricted to a single star acting as a capturing group.

Thoughts ?

@smarie smarie changed the title AUTO cases cannot be used from test files with other prefix, such as bench_*.py. Even if the latter are correct test files according to python_files. AUTO cases cannot be used from test files with non-test prefix, such as bench_*.py. Even if the latter are correct test files according to python_files. Jan 13, 2024
@mroeschke
Copy link

Thanks for writing this up.

Looks like the pytest Config object should be able to access python_files (or any other config): https://docs.pytest.org/en/7.1.x/reference/reference.html#config

Yeah given the design of AUTO your mapping idea may be the only viable one; for every pattern in python_files.py AUTO looks in that file modified (prepended, appended) by cases

@smarie
Copy link
Owner Author

smarie commented Jan 16, 2024

Thanks @mroeschke for your feedback ! Not sure when this can get implemented but it will be the next mod to implement for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants