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

Parse args from file #12085

Merged
merged 8 commits into from
Mar 9, 2024
Merged

Parse args from file #12085

merged 8 commits into from
Mar 9, 2024

Conversation

levsa
Copy link
Contributor

@levsa levsa commented Mar 6, 2024

Fixes #11871 using the proposed solution in #11871 (comment)

Adds support for reading file_or_dir positional arguments from a file
using the prefix character '@', like e.g.:

pytest @tests.txt

Added tests, but not sure how/where to add documentation, I'm guessing it should be in the output of pytest --help?

@levsa levsa force-pushed the parse_args_from_file branch from 459f778 to 8f021a2 Compare March 7, 2024 09:10
@levsa
Copy link
Contributor Author

levsa commented Mar 7, 2024

I don't understand why the test fails on py310 and py311. It seems to do it only when running with tox, it passes when running with virtual env manually (based on 3.10.2). Some issue with default encoding for open() missing in argparse.py, probably because tox.ini has PYTHONWARNDEFAULTENCODING=1?

@bluetech
Copy link
Member

bluetech commented Mar 7, 2024

It's a Python bug python/cpython#85308 that it seems was only fixed in Python 3.12. So we should ignore EncodingWarnings for this test, see here how to do it: https://docs.pytest.org/en/stable/how-to/capture-warnings.html#pytest-mark-filterwarnings

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Can you also add a test using pytester to testing/acceptance_test.py? This will make sure it works end-to-end.

changelog/11871.feature.rst Outdated Show resolved Hide resolved
@levsa
Copy link
Contributor Author

levsa commented Mar 7, 2024

Thanks!

Can you also add a test using pytester to testing/acceptance_test.py? This will make sure it works end-to-end.

Sure!

@bluetech
Copy link
Member

bluetech commented Mar 7, 2024 via email

@levsa levsa force-pushed the parse_args_from_file branch 3 times, most recently from 24675ae to bc68ed1 Compare March 7, 2024 20:52
@levsa
Copy link
Contributor Author

levsa commented Mar 8, 2024

Thanks!
Can you also add a test using pytester to testing/acceptance_test.py? This will make sure it works end-to-end.

Sure!

Acceptance test added.

@levsa levsa force-pushed the parse_args_from_file branch from bc68ed1 to 4e530e1 Compare March 8, 2024 07:57
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small comments, but with them I think this is good to go.

testing/acceptance_test.py Show resolved Hide resolved
testing/acceptance_test.py Outdated Show resolved Hide resolved
testing/acceptance_test.py Show resolved Hide resolved
testing/test_parseopt.py Show resolved Hide resolved
@levsa levsa force-pushed the parse_args_from_file branch from 56bac60 to a413282 Compare March 8, 2024 12:14
@levsa
Copy link
Contributor Author

levsa commented Mar 8, 2024

A few small comments, but with them I think this is good to go.

Thanks! Updated now.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks!

We should add this feature to the docs, I think here is a good place to mention it:

https://docs.pytest.org/en/stable/how-to/usage.html#specifying-which-tests-to-run

@levsa
Copy link
Contributor Author

levsa commented Mar 8, 2024

Great work, thanks!

We should add this feature to the docs, I think here is a good place to mention it:

https://docs.pytest.org/en/stable/how-to/usage.html#specifying-which-tests-to-run

I made an attempt, please check if it works :)

@levsa levsa force-pushed the parse_args_from_file branch 2 times, most recently from 5a98980 to f66dbf5 Compare March 8, 2024 15:33
@levsa levsa force-pushed the parse_args_from_file branch from f66dbf5 to 1cf0413 Compare March 8, 2024 15:36
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

doc/en/how-to/usage.rst Show resolved Hide resolved
@bluetech bluetech merged commit 9033d4d into pytest-dev:main Mar 9, 2024
24 checks passed
flying-sheep pushed a commit to flying-sheep/pytest that referenced this pull request Apr 9, 2024
Co-authored-by: Ran Benita <[email protected]>
Co-authored-by: Bruno Oliveira <[email protected]>
@patrickvonplaten
Copy link

That's a very nice feature - can it also read in parameterized tests though such as:
pytest tests/tasks_test.py::test_task_scoring[param_1]

from a file?

It doesn't seem to find them

@The-Compiler
Copy link
Member

@patrickvonplaten The tests added in this PR test exactly that. I suggest you open a new issue with more information and a reproducer.

@patrickvonplaten
Copy link

Actually everything works just fine - sorry for the noise

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

Successfully merging this pull request may close these issues.

Proposing a new flag, --list-of-files-or-dirs, to compliment the positional file_or_dir argument
5 participants