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

Test selection syntax is baroque and foreign #2193

Open
nedbat opened this issue Jan 13, 2017 · 7 comments
Open

Test selection syntax is baroque and foreign #2193

nedbat opened this issue Jan 13, 2017 · 7 comments
Labels
topic: collection related to the collection phase type: enhancement new feature or API change, should be merged into features branch

Comments

@nedbat
Copy link
Contributor

nedbat commented Jan 13, 2017

When I want to run a single test, I have to use an odd double-colon syntax:

$ pytest tests/test_api.py::ReportIncludeOmitTest::test_include

Double-colons appear nowhere in Python. If the test fails, pytest even reports the failure to me using the usual single-dot syntax:

=================================== FAILURES ===================================
______________________ ReportIncludeOmitTest.test_include ______________________

Please allow the more usual single-dot syntax, and perhaps a single colon between file and class?

$ pytest tests/test_api.py:ReportIncludeOmitTest.test_include

Versions:

$ pytest --version
This is pytest version 3.0.5, imported from /usr/local/virtualenvs/coverage/lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
  pytest-xdist-1.15.0 at /usr/local/virtualenvs/coverage/lib/python2.7/site-packages/xdist/boxed.py
  pytest-xdist-1.15.0 at /usr/local/virtualenvs/coverage/lib/python2.7/site-packages/xdist/looponfail.py
  pytest-xdist-1.15.0 at /usr/local/virtualenvs/coverage/lib/python2.7/site-packages/xdist/plugin.py
  pytest-warnings-0.2.0 at /usr/local/virtualenvs/coverage/lib/python2.7/site-packages/pytest_warnings/__init__.pyc
@nicoddemus
Copy link
Member

Hi @nedbat, thanks for writing.

I agree the current style is a little odd, but for backward compatibility reasons it is here to stay.

Your suggestion:

$ pytest tests/test_api.py:ReportIncludeOmitTest.test_include

As an addition to the current style is probably doable, I think.

@nicoddemus nicoddemus added the type: enhancement new feature or API change, should be merged into features branch label Jan 13, 2017
@nedbat
Copy link
Contributor Author

nedbat commented Jan 14, 2017

If we wanted to be truly convenient, then accept a variety of punctuation, etc, and figure it out.

tests/test_api.py:ReportIncludeOmitTest.test_include
tests/test_api.py.ReportIncludeOmitTest.test_include
tests/test_api:ReportIncludeOmitTest.test_include
tests.test_api:ReportIncludeOmitTest.test_include
tests.test_api.ReportIncludeOmitTest.test_include

etc. What's the harm in finding the thing the user must have meant?

@RonnyPfannschmidt
Copy link
Member

@nedbat the main harm in pretending to understand the user is getting it wrong - which is easy

for example argparse does it in python by default, and it creates bad bugs in py.test for early parsing of cli args where a plugin registers an option that matches the prefix of a core option while having different semantics

if it was an opt-in like --pyargs it would be more easy to work with it/reason about it

@nedbat
Copy link
Contributor Author

nedbat commented Jan 19, 2017

@RonnyPfannschmidt OK, I knew the "dwim" feature idea might be unpopular. Are you ok with the "foo.py:class.method" syntax?

@RonnyPfannschmidt
Copy link
Member

@nedbat i like that syntax, it may even be a good idea to eventually switch over to it

we just have to consider time-frames, and we should figure a consistent way to express parameters with it

@nicoddemus
Copy link
Member

we should figure a consistent way to express parameters with it

Do you foresee any problems with it @RonnyPfannschmidt? I didn't look too much into it, but I think the first step would be to find all places where there's some handling of the current syntax ("::") and replace those by thin wrappers. After that, it would be a matter of adding support for the new syntax in those thin wrappers. Of course that's a simplistic version and there might be other problems that I'm not foreseeing.

@RonnyPfannschmidt
Copy link
Member

@nicoddemus i'm under the impression this one will be one of those hindsight things as well ^^

@Zac-HD Zac-HD added the topic: collection related to the collection phase label Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

4 participants