2

Suppose I have a fixture fixture1 and I want to be able to skip all tests that use this fixture from pytest commandline. I found answer to this quetion, but I decided to do it different way. I am marking all tests that uses fixture1 with using_fixture1 marker by defining following in my conftest.py

def pytest_collection_modifyitems(items):
    for item in items:
        try:
            fixtures=item.fixturenames
            if 'fixture1' in fixtures:
                item.add_marker(pytest.mark.using_fixture1)
        except:
            pass

And then, when running pytest I use: py.test tests -m "not using_fixture1".

So the real question should be: Are there any better ways to do it and are there any drawbacks of my solution?

Community
  • 1
  • 1
running.t
  • 5,329
  • 3
  • 32
  • 50
  • If it does what you need, that's the important thing, isn't it? :) – pfctdayelise Jan 18 '16 at 04:21
  • You can add `parser.parameter` at hook `pytest_addoption`. Then check this parameter by using `request.config.getoption` method and if so, call for `raise pytest.skip('skip me by cmdline opt')`. – Sergei Voronezhskii Mar 18 '16 at 16:14

0 Answers0