]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/conftest.py
2 Topotest conftest.py file.
5 from lib
.topogen
import get_topogen
, diagnose_env
6 from lib
.topotest
import json_cmp_result
7 from lib
.topolog
import logger
10 def pytest_addoption(parser
):
12 Add topology-only option to the topology tester. This option makes pytest
13 only run the setup_module() to setup the topology without running any tests.
15 parser
.addoption('--topology-only', action
='store_true',
16 help='Only set up this topology, don\'t run tests')
18 def pytest_runtest_call():
20 This function must be run after setup_module(), it does standarized post
21 setup routines. It is only being used for the 'topology-only' option.
23 # pylint: disable=E1101
24 # Trust me, 'config' exists.
25 if pytest
.config
.getoption('--topology-only'):
28 # Allow user to play with the setup.
31 pytest
.exit('the topology executed successfully')
33 def pytest_assertrepr_compare(op
, left
, right
):
35 Show proper assertion error message for json_cmp results.
38 if not isinstance(json_result
, json_cmp_result
):
40 if not isinstance(json_result
, json_cmp_result
):
43 return json_result
.errors
45 def pytest_configure(config
):
46 "Assert that the environment is correctly configured."
47 if not diagnose_env():
48 pytest
.exit('enviroment has errors, please read the logs')
50 def pytest_runtest_makereport(item
, call
):
51 "Log all assert messages to default logger with error level"
53 if call
.excinfo
is None:
57 modname
= parent
.module
.__name
__
59 # Treat skips as non errors
60 if call
.excinfo
.typename
!= 'AssertionError':
61 logger
.info('assert skipped at "{}/{}": {}'.format(
62 modname
, item
.name
, call
.excinfo
.value
))
65 # Handle assert failures
66 parent
._previousfailed
= item
67 logger
.error('assert failed at "{}/{}": {}'.format(
68 modname
, item
.name
, call
.excinfo
.value
))