Skip to content

parametrized test nodes cannot be specified to run on the command line #649

Closed
@pytestbot

Description

@pytestbot

Originally reported by: Alfredo Deza (BitBucket: alfredodeza, GitHub: alfredodeza)


If a file called test_foo.py has a test_add function, the normal notation to call that specific function on the command line is:

py.test /path/to/test_foo::test_add

But if the function is parametrized the node ids change (seen with high verbosity and --collect-only) at runtime, so it makes it impossible to specify any parametrized test to run unless one just points to the whole file (as opposed to a single test node)

It would be nice if there was a way to specify such parametrized test nodes to run. Currently the behavior is that py.test will error with:

#!

(tmp)papaya-2 ~/tmp ᓆ py.test -vvv "/Users/alfredo/tmp/test_fail.py::test_adding"
============================== test session starts ==============================
platform darwin -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2 -- /Users/alfredo/.virtualenvs/tmp/bin/python
collecting 3 itemsERROR: not found: /Users/alfredo/tmp/test_fail.py::test_adding
(no name '/Users/alfredo/tmp/test_fail.py::test_adding' in any of [<Module 'test_fail.py'>])

===============================  in 0.01 seconds ================================

The contents of the test is:

#!

(tmp)papaya-2 ~/tmp ᓆ cat test_fail.py
import pytest


@pytest.mark.parametrize(('inp', 'expected'),
[
    ('2 + 2', 4),
    ('0 + 0', 0),
    ('2 + 2.0', 4.0),
])
def test_adding(inp, expected):
    assert eval(inp) == expected

This affects pytest.vim as it relies heavily on this particular feature so that a user can run specific tests from Vim.

pytest.vim related issue: alfredodeza/pytest.vim#23


Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: parametrizerelated to @pytest.mark.parametrizetopic: selectionrelated to test selection from the command linetype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions