Skip to content

Simplify running parametrized tests by node ID #1360

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
shapiy opened this issue Feb 5, 2016 · 8 comments
Closed

Simplify running parametrized tests by node ID #1360

shapiy opened this issue Feb 5, 2016 · 8 comments
Labels
topic: parametrize related to @pytest.mark.parametrize topic: selection related to test selection from the command line type: enhancement new feature or API change, should be merged into features branch

Comments

@shapiy
Copy link

shapiy commented Feb 5, 2016

Please consider such a case. Contents of test_mod.py:

class TestClass(object):
    @pytest.mark.parametrize('date', [datetime.date.today()])
    def test_method(self):
        pass

So, to run the particular test method, I need to call the command:

py.test test_mod.py::TestClass::test_method[date0]

But if there are two parameter values, it's not gonna work. Also, I need to keep in mind how parameters of different types are mapped to ID parts. Currently I do this:

py.test test_mod.py::TestClass -k test_method

But it would be really nice to run the method (including all parameters) simply by truncating the square brackets:

py.test test_mod.py::TestClass::test_method
@RonnyPfannschmidt
Copy link
Member

that feature is in the list

its currently unreliable to implement due to collection being misshaped,
as collectors materialize parametrization of items instead of the items having parametrized calls as sub nodes

@RonnyPfannschmidt
Copy link
Member

would acceptable alternative solution to your case be to give the randomized item a hardcoded id, so the test name is test_mod.py::TestClass::test_method[today]

@Apteryks
Copy link

I too was bitten by this limitation. The documentation here clearly states that:

py.test test_mod.py::test_func # only run tests that match the "node ID",
# e.g "test_mod.py::test_func" will select
# only test_func in test_mod.py

I would have expected doing py.test test_mod.py::TestClass::test_method to run the parametrized test with all the parameters.

@Apteryks
Copy link

Also, the scheme used by shapiy to access the first parametrized parameter 'date' (if I understand correctly) doesn't seem to work for every object type.

For example, this works with py.test test_mod.py::test_foo[someparameter0]

@pytest.mark.parametrize('someparameter', [object()])
def test_foo(someparameter):
    pass

But the following doesn't (it returns: ERROR: not found: /home/user/test_mod.py::test_foo[someparameter0])

@pytest.mark.parametrize('someparameter', ['some string'])
def test_foo(someparameter):
    pass

And what happens when a parametrized test takes multiple parameters? I don't think the current scheme of appending the parametrized iteration to the parameter name makes much sense. What I would like to be able to do would rather be:

py.test test_mod.py::test_foo[0] for the first parametrized set of params,
py.test test_mod.py::test_foo[1] for the second, etc.

@nicoddemus
Copy link
Member

@Apteryks I agree with your points... I'm not sure how easy it is to support them under the current architecture though.

@goodboy
Copy link

goodboy commented Mar 31, 2016

@Apteryks @shapiy As a workaround for now you guys might find pytest-interactive handy.

I originally tossed it together to accommodate making more complex selections of dynamically generated tests from the cli. It's been on the back burner for far too long and I've been meaning to write tests for it as required by plugincompat before throwing it up on PyPI.

The whole idea is to select tests after all test gen is complete using IPython's attribute tab-completion facilities. I'd like to add fuzzy matching support eventually as well. It's basically a "generate then filter" approach as opposed to expecting the user to know pytest's internal dynamically generated names convention at the inset.

@Apteryks
Copy link

@tgoodlet, thank you for letting us know about this project of yours, it does seem very promising! I'll be trying it soon :)

@Zac-HD Zac-HD added type: enhancement new feature or API change, should be merged into features branch topic: parametrize related to @pytest.mark.parametrize topic: selection related to test selection from the command line labels Oct 20, 2018
@bluetech
Copy link
Member

This does work these days (although it's implemented with a hack).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: parametrize related to @pytest.mark.parametrize topic: selection related to test selection from the command line type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

7 participants