SHARE
TWEET

Untitled

a guest Jun 17th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """confest.py file."""
  2. import pytest
  3.  
  4.  
  5. def pytest_addoption(parser):
  6.     parser.addoption(
  7.         "--cmdopt", action="store", default=None
  8.     )
  9. @pytest.fixture(scope="session", autouse=True)
  10. def cmdopt(request):
  11.     """Reading data from command prompt."""
  12.     return request.config.getoption("--cmdopt")
  13.  
  14. @pytest.fixture(scope="session", autouse=True)
  15. def do_something(cmdopt)
  16.     """Would need to preprocess the needed one to make it parameterised."""
  17.     return list_of_tuples
  18.      
  19. """ Test Suite File."""
  20. import pytest
  21.  
  22. #do_something is in conftest file
  23. @pytest.mark.parametrize("val1,val2", variables = do_something)
  24. def test_case1(val1, val2):
  25.     assert val1 == val2
  26.      
  27. # conftest.py
  28. import pytest
  29.  
  30.  
  31. def pytest_addoption(parser):
  32.     parser.addoption('--range', action='store', type=int, default=None)
  33.  
  34.  
  35. def pytest_generate_tests(metafunc):
  36.     if all(arg in metafunc.fixturenames for arg in ('val1', 'val2')):
  37.         hi = metafunc.config.getoption('--range')
  38.         if hi is not None:
  39.             variables = [(i, i) for i in range(hi)]
  40.         metafunc.parametrize("val1,val2", variables)
  41.      
  42. def test_case1(val1, val2):
  43.     assert val1 == val2
  44.      
  45. $ pytest -v --range 1
  46. ...
  47. test_spam.py::test_case1[0-0] PASSED
  48. ...
  49. $ pytest -v --range 5
  50. ...
  51. test_spam.py::test_case1[0-0] PASSED
  52. test_spam.py::test_case1[1-1] PASSED
  53. test_spam.py::test_case1[2-2] PASSED
  54. test_spam.py::test_case1[3-3] PASSED
  55. test_spam.py::test_case1[4-4] PASSED
  56. ...
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top