]>
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
12 def pytest_addoption(parser
):
14 Add topology-only option to the topology tester. This option makes pytest
15 only run the setup_module() to setup the topology without running any tests.
17 parser
.addoption('--topology-only', action
='store_true',
18 help='Only set up this topology, don\'t run tests')
20 def pytest_runtest_call():
22 This function must be run after setup_module(), it does standarized post
23 setup routines. It is only being used for the 'topology-only' option.
30 # Allow user to play with the setup.
33 pytest
.exit('the topology executed successfully')
35 def pytest_assertrepr_compare(op
, left
, right
):
37 Show proper assertion error message for json_cmp results.
40 if not isinstance(json_result
, json_cmp_result
):
42 if not isinstance(json_result
, json_cmp_result
):
45 return json_result
.errors
47 def pytest_configure(config
):
48 "Assert that the environment is correctly configured."
52 if not diagnose_env():
53 pytest
.exit('enviroment has errors, please read the logs')
55 if config
.getoption('--topology-only'):
58 def pytest_runtest_makereport(item
, call
):
59 "Log all assert messages to default logger with error level"
61 if call
.excinfo
is None:
65 modname
= parent
.module
.__name
__
67 # Treat skips as non errors
68 if call
.excinfo
.typename
!= 'AssertionError':
69 logger
.info('assert skipped at "{}/{}": {}'.format(
70 modname
, item
.name
, call
.excinfo
.value
))
73 # Handle assert failures
74 parent
._previousfailed
= item
75 logger
.error('assert failed at "{}/{}": {}'.format(
76 modname
, item
.name
, call
.excinfo
.value
))
78 # (topogen) Set topology error to avoid advancing in the test.
81 # This will cause topogen to report error on `routers_have_failure`.
82 tgen
.set_error('{}/{}'.format(modname
, item
.name
))