Skip to content

Re-allow simple class::test selection via "-k" #765

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

Closed
pytestbot opened this issue Jun 9, 2015 · 9 comments
Closed

Re-allow simple class::test selection via "-k" #765

pytestbot opened this issue Jun 9, 2015 · 9 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: BitBucket: pchambon, GitHub: pchambon


Long ago, it was possible to simply copy-paste the name of a failed test (in the form MyClass.my_test"), from the output of a run, to rerun only that tests thanks to the "-k" option.

Now that the "-k" has much evolved, one is forced to rewrite with spaces and logical operators, which is quite unhandy when going through a heavy test suite with miscellaneous failing tests.

I see that the new output uses double dots instead:

"test_abstract_processing.py::TestUserRetriever::test_user_retrieval"

Wouldn't it then be a good idea to automatically recognize that alternative syntax in the "-k" option, or even in another option dedicated for that ?


@pytestbot
Copy link
Contributor Author

Original comment by Bruno Oliveira (BitBucket: nicoddemus, GitHub: nicoddemus):


I agree it would be interesting to support this feature out of the box... not sure another option is the better UI, as a user I prefer to just have to remember one of the options.

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: pchambon, GitHub: pchambon:


I haven't studied the code yet, but I guess a simple string operation replacing "test_abstract_processing.py::TestUserRetriever::test_user_retrieval" by "(test_abstract_processing.py and TestUserRetriever and test_user_retrieval)" would do the trick, right ?

@pytestbot
Copy link
Contributor Author

Original comment by Bruno Oliveira (BitBucket: nicoddemus, GitHub: nicoddemus):


I also haven't studied the code, but if you are willing to work on a PR you're more than welcome! 😄

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: pchambon, GitHub: pchambon:


I've done a quick POC with regexes, I'll have a look at doing a proper PR with additional tests.

#!python

    # we recognize keywords in the form "[myfile.py::]MyClass::my_test", as output by py.test,
    # but we ignore the "myfile.py" part and only consider class and function substrings
    def _colon_pair_replacer(match_obj):
        return "(%s and %s)" % (match_obj.group(2), match_obj.group(3))
    keywordexpr = re.sub(r'\b(\S*?::)?(\w+)::(\w+)(\b|\s)', _colon_pair_replacer, keywordexpr, flags=re.IGNORECASE | re.UNICODE)

@pytestbot
Copy link
Contributor Author

Original comment by Bruno Oliveira (BitBucket: nicoddemus, GitHub: nicoddemus):


Thanks, please post here if you have any questions on how to properly test this.

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: pchambon, GitHub: pchambon:


Hum, are pytest tests supposed to run on windows ?
I kinda reproduced what the Makefile was supposed to do, activated the venv, and ran "python runtox.py -e py27,py34,flakes -vvv", but all I get is two tracebacks like below (for python2 and python3, whereas latest colorama is installed on both), and a listing of all the tests marked as "skipped". Maybe a bug due to path separator \ vs / ?

#!python

Traceback (most recent call last):
  File "P:\Websites\pytest\.tox\py34\Scripts\py.test-script.py", line 5, in <module>
    from pkg_resources import load_entry_point
  File "P:\Websites\pytest\.tox\py34\lib\site-packages\pkg_resources.py", line 2829, in <module>
    working_set = WorkingSet._build_master()
  File "P:\Websites\pytest\.tox\py34\lib\site-packages\pkg_resources.py", line 449, in _build_master
    ws.require(__requires__)
  File "P:\Websites\pytest\.tox\py34\lib\site-packages\pkg_resources.py", line 742, in require
    needed = self.resolve(parse_requirements(requirements))
  File "P:\Websites\pytest\.tox\py34\lib\site-packages\pkg_resources.py", line 639, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: colorama
ERROR: InvocationError: 'P:\\Websites\\pytest\\.tox\\py34\\Scripts\\py.test.EXE --lsof -rfsxX --junitxml=P:\\Websites\\pytest\\.tox\\py34\\log/junit-py34.xml -vv'
....

=========================== short test summary info ===========================
SKIP [66] P:\Websites\pytest\.tox\flakes\lib\site-packages\pytest_flakes.py:73: file(s) previously passed pyflakes checks

@pytestbot
Copy link
Contributor Author

Original comment by Bruno Oliveira (BitBucket: nicoddemus, GitHub: nicoddemus):


Yes, it runs on Windows just fine... in a virtualenv, this should be enough:

$ pip install tox
$ tox -e py27,py34,flakes

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: pchambon, GitHub: pchambon:


Ok thanks, it eventually worked, it seems that the fact that the dev "_pytest" was directly importable in my python2 screwed things up.

I've done a PR, realized too late that it was on "default" branch, I hope it can work still (else just tell me) :
https://bitbucket.org/pytest-dev/pytest/pull-request/305/allow-selection-with-myfilepy-myfile/diff

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@flub
Copy link
Member

flub commented Jul 24, 2015

This was implemented in PR #806 but it was decided to not cover this in -k as test ID is already suitably covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

2 participants