Run py.test test case inside any python class

I wanted a way to run the current test I was editing when I know the name of the method, but I’m too lazy to scroll up and see which class it’s defined in and then have to type that out as well. So I found a way for py.test to run any test in any class in a file by just giving it the name of that test or part of its name.

Instead of typing:

$ py.test path/to/my/test/

I can just type:

$ py.test path/to/my/test/ -k test_my_thing

Or even:

$ py.test path/to/my/test/ -k test_my

Or even:

$ py.test path/to/my/test/ -k "thing or stuff"

Woo py.test!

FWIW, nosetests can also do this with the -m option which supports regexp. But AFAIK it does not support the human-friendly " or " interface like in the last example above.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.