I have a test fixture with session
scope which is parametrized, e.g.
@pytest.fixture(scope="session", params=["one", "two", "three"])
def myfixture():
...
In my directory, I have files which use pytest.mark.usefixtures("myfixture")
and one file which contains tests should be run only for myfixture
with "two"
parameter and py.test should skip it otherwise.
Are there any ways to achieve this in py.test or do I need to set a special variable in some class in myfixture()
function?
The simplest way to skip a test is to mark it with the skip decorator which may be passed an optional reason . It is also possible to skip imperatively during test execution or setup by calling the pytest. skip(reason) function. This is useful when it is not possible to evaluate the skip condition during import time.
The skip is one such marker provided by pytest that is used to skip test functions from executing. We can specify why we skip the test case using the reason argument of the skip marker.
Use warnings. filterwarnings() to ignore deprecation warnings Call warnings. filterwarnings(action, category=DeprecationWarning) with action as "ignore" and category set to DeprecationWarning to ignore any deprecation warnings that may rise.
Running pytest We can run a specific test file by giving its name as an argument. A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m .
Found solution myself, one can define function in conftest.py
:
def pytest_namespace():
return {"param": None}
And in fixture function we can do:
@pytest.fixture(scope="session", params=["one", "two", "three"])
def myfixture():
pytest.param = request.param
# ...
So we can wrap test class with:
@pytest.mark.skipif("pytest.param == 'value'")
class TestSmth(object):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With