[TIP] pytest test collection problem with markers and test parametrization?

Pella,Chris Chris.Pella at safenet-inc.com
Mon Apr 8 11:38:28 PDT 2013

I asked this question in stackoverflow but didn't get any answers, so I'll narrowcast it here.
We have a marked test that we expect to be not executed because py.test was invoked with another marker, yet the test is getting executed.
def test_one(some_fixture):

def test_two(some_fixture):

If we run with pytest -collectonly -m "sa" it will show that both tests are collected, but we expected test_one to not be collected for execution. The only way to avoid the stress test is by invoking pytest --collectonly -m "sa and (not stress)".
We inspect the original argument list in the pytest_generate_tests hook to grab the markers so we can use the platform (e.g. sa in this case) marker in the fixture to set up the test resources, but otherwise don't manipulate the arguments.  Is the test parametrization hook below causing pytest to think test_one is marked with the 'sa' marker?

def pytest_generate_tests(metafunc):
    Generate the parameterization list for the source device
    based on the markers set in the command line.
    @param metafunc - meta object for a specific function.
    source    = [ 'unsupported' ]

    if '-m' in metafunc.config._origargs:
        index = metafunc.config._origargs.index('-m')
        markers = metafunc.config._origargs[index + 1]
        markers = markers.split(',')

        source = []
        if 'sa' in markers:
            source.append( 'sa' )
        if 'g5' in markers:
            source.append( 'g5' )
        if 'pci' in markers:
            source.append( 'pci' )
        if len(source) == 0:
            source = [ 'unsupported' ]

    if 'source' in metafunc.funcargnames:
        metafunc.parametrize("source", source, indirect=True)
    if 'rped_source_only' in metafunc.funcargnames:
        metafunc.parametrize("rped_source_only", source, indirect=True)


The information contained in this electronic mail transmission 
may be privileged and confidential, and therefore, protected 
from disclosure. If you have received this communication in 
error, please notify us immediately by replying to this 
message and deleting it from your computer without copying 
or disclosing it.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130408/5b8c8054/attachment.htm>

More information about the testing-in-python mailing list