]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/conftest.py
Merge pull request #3174 from opensourcerouting/feature/isis-triggered-hello
[mirror_frr.git] / tests / topotests / conftest.py
1 """
2 Topotest conftest.py file.
3 """
4
5 from lib.topogen import get_topogen, diagnose_env
6 from lib.topotest import json_cmp_result
7 from lib.topolog import logger
8 import pytest
9
10 def pytest_addoption(parser):
11 """
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.
14 """
15 parser.addoption('--topology-only', action='store_true',
16 help='Only set up this topology, don\'t run tests')
17
18 def pytest_runtest_call():
19 """
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.
22 """
23 # pylint: disable=E1101
24 # Trust me, 'config' exists.
25 if pytest.config.getoption('--topology-only'):
26 tgen = get_topogen()
27 if tgen is not None:
28 # Allow user to play with the setup.
29 tgen.mininet_cli()
30
31 pytest.exit('the topology executed successfully')
32
33 def pytest_assertrepr_compare(op, left, right):
34 """
35 Show proper assertion error message for json_cmp results.
36 """
37 json_result = left
38 if not isinstance(json_result, json_cmp_result):
39 json_result = right
40 if not isinstance(json_result, json_cmp_result):
41 return None
42
43 return json_result.errors
44
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')
49
50 def pytest_runtest_makereport(item, call):
51 "Log all assert messages to default logger with error level"
52 # Nothing happened
53 if call.excinfo is None:
54 return
55
56 parent = item.parent
57 modname = parent.module.__name__
58
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))
63 return
64
65 # Handle assert failures
66 parent._previousfailed = item
67 logger.error('assert failed at "{}/{}": {}'.format(
68 modname, item.name, call.excinfo.value))