|
| 1 | +"""Provide some base configurations for tests.""" |
| 2 | +import pytest |
| 3 | +import py.path # pyright: reportMissingModuleSource=false |
| 4 | + |
| 5 | + |
| 6 | +TEST_CASES_PATH = py.path.local(__file__).realpath() / '..' / 'test_cases' |
| 7 | + |
| 8 | + |
| 9 | +def find_all_test_cases(): |
| 10 | + """Generate list of test cases. |
| 11 | +
|
| 12 | + :yield: generates each test case as list item |
| 13 | + :rtype: str |
| 14 | + """ |
| 15 | + for c in TEST_CASES_PATH.listdir(sort=True): |
| 16 | + c = c.basename |
| 17 | + if c.endswith('.py'): |
| 18 | + yield c.replace('.py', '') |
| 19 | + |
| 20 | + |
| 21 | +TEST_CASES = list(find_all_test_cases()) |
| 22 | + |
| 23 | + |
| 24 | +def pytest_addoption(parser): |
| 25 | + """Change command line options defaults. |
| 26 | +
|
| 27 | + We want run our tests only in three modes |
| 28 | + `live` - interact with an existing API |
| 29 | + `record` - interact with an existing API and record the interactions |
| 30 | + `replay` - replay previouly recorded interactions with API |
| 31 | +
|
| 32 | + :param parser: A parser object |
| 33 | + :type parser: object parser |
| 34 | + """ |
| 35 | + parser.addoption( |
| 36 | + "--vcrmode", |
| 37 | + action="store", |
| 38 | + default="replay", |
| 39 | + choices=["replay", "record", "live"], |
| 40 | + help="mode for vcr recording; one of ['replay', 'record', 'live']", |
| 41 | + ) |
| 42 | + |
| 43 | + |
| 44 | +@pytest.fixture |
| 45 | +def vcrmode(request): |
| 46 | + """Return vcrmode of a request. |
| 47 | +
|
| 48 | + :param request: A request object |
| 49 | + :type request: object request |
| 50 | + :return: vcrmode |
| 51 | + :rtype: str |
| 52 | + """ |
| 53 | + return request.config.getoption("vcrmode") |
| 54 | + |
| 55 | + |
| 56 | +def cassette_name(test_name=None): |
| 57 | + """Generate cassette_name.""" |
| 58 | + return 'tests/fixtures/{0}.yml'.format(test_name) |
0 commit comments