Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """confest.py file."""
- import pytest
- def pytest_addoption(parser):
- parser.addoption(
- "--cmdopt", action="store", default=None
- )
- @pytest.fixture(scope="session", autouse=True)
- def cmdopt(request):
- """Reading data from command prompt."""
- return request.config.getoption("--cmdopt")
- @pytest.fixture(scope="session", autouse=True)
- def do_something(cmdopt)
- """Would need to preprocess the needed one to make it parameterised."""
- return list_of_tuples
- """ Test Suite File."""
- import pytest
- #do_something is in conftest file
- @pytest.mark.parametrize("val1,val2", variables = do_something)
- def test_case1(val1, val2):
- assert val1 == val2
- # conftest.py
- import pytest
- def pytest_addoption(parser):
- parser.addoption('--range', action='store', type=int, default=None)
- def pytest_generate_tests(metafunc):
- if all(arg in metafunc.fixturenames for arg in ('val1', 'val2')):
- hi = metafunc.config.getoption('--range')
- if hi is not None:
- variables = [(i, i) for i in range(hi)]
- metafunc.parametrize("val1,val2", variables)
- def test_case1(val1, val2):
- assert val1 == val2
- $ pytest -v --range 1
- ...
- test_spam.py::test_case1[0-0] PASSED
- ...
- $ pytest -v --range 5
- ...
- test_spam.py::test_case1[0-0] PASSED
- test_spam.py::test_case1[1-1] PASSED
- test_spam.py::test_case1[2-2] PASSED
- test_spam.py::test_case1[3-3] PASSED
- test_spam.py::test_case1[4-4] PASSED
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement