import pytest
@pytest.fixture()
def fixture1():
print "Fixture 1"
@pytest.fixture()
def fixture2():
print "Fixture 2"
В pytest_addoption в опциональных аргументах default убрать кавычки вокруг None и использовать
Маркер skipif:
import pytest
def skip_non_matching_url(option):
return pytest.mark.skipif(
not getattr(pytest.config.option, option, None),
reason="Url doesn't match command line option"
)
@skip_non_matching_url("url2")
def test_my_url2(fixture2):
print "Test my url2"
@skip_non_matching_url("url1")
def test_my_url1(fixture1):
print "Test my ulr1"
$ python -m pytest -vs --url1 ya.ru
collected 2 items
test_something.py::test_my_url2 SKIPPED
test_something.py::test_my_url1 Fixture 1
Test my ulr1
PASSED
$ python -m pytest -vs --url2 ya.ru
collected 2 items
test_something.py::test_my_url2 Fixture 2
Test my url2
PASSED
test_something.py::test_my_url1 SKIPPED
Или кастомные маркеры:
import pytest
@pytest.mark.url2
def test_my_url2(fixture2):
print "Test my url2"
@pytest.mark.url1
def test_my_url1(fixture1):
print "Test my ulr1"
$ python -m pytest -vs -m url2
collected 2 items
test_something.py::test_my_url2 Fixture 2
Test my url2
PASSED
$ python -m pytest -vs -m url1
collected 2 items
test_something.py::test_my_url1 Fixture 1
Test my ulr1
PASSED