]>
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
13 def pytest_addoption(parser
):
15 Add topology-only option to the topology tester. This option makes pytest
16 only run the setup_module() to setup the topology without running any tests.
21 help="Only set up this topology, don't run tests",
25 def pytest_runtest_call():
27 This function must be run after setup_module(), it does standarized post
28 setup routines. It is only being used for the 'topology-only' option.
35 # Allow user to play with the setup.
38 pytest
.exit("the topology executed successfully")
41 def pytest_assertrepr_compare(op
, left
, right
):
43 Show proper assertion error message for json_cmp results.
46 if not isinstance(json_result
, json_cmp_result
):
48 if not isinstance(json_result
, json_cmp_result
):
51 return json_result
.gen_report()
54 def pytest_configure(config
):
55 "Assert that the environment is correctly configured."
59 if not diagnose_env():
60 pytest
.exit("enviroment has errors, please read the logs")
62 if config
.getoption("--topology-only"):
66 def pytest_runtest_makereport(item
, call
):
67 "Log all assert messages to default logger with error level"
69 if call
.excinfo
is None:
73 modname
= parent
.module
.__name
__
75 # Treat skips as non errors
76 if call
.excinfo
.typename
!= "AssertionError":
78 'assert skipped at "{}/{}": {}'.format(
79 modname
, item
.name
, call
.excinfo
.value
84 # Handle assert failures
85 parent
._previousfailed
= item
87 'assert failed at "{}/{}": {}'.format(modname
, item
.name
, call
.excinfo
.value
)
90 # (topogen) Set topology error to avoid advancing in the test.
93 # This will cause topogen to report error on `routers_have_failure`.
94 tgen
.set_error("{}/{}".format(modname
, item
.name
))