diff options
Diffstat (limited to 'tests/topotests/conftest.py')
| -rwxr-xr-x | tests/topotests/conftest.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/tests/topotests/conftest.py b/tests/topotests/conftest.py index 76b0ab017e..d46c52a4c4 100755 --- a/tests/topotests/conftest.py +++ b/tests/topotests/conftest.py @@ -9,13 +9,18 @@ import pytest topology_only = False + def pytest_addoption(parser): """ Add topology-only option to the topology tester. This option makes pytest only run the setup_module() to setup the topology without running any tests. """ - parser.addoption('--topology-only', action='store_true', - help='Only set up this topology, don\'t run tests') + parser.addoption( + "--topology-only", + action="store_true", + help="Only set up this topology, don't run tests", + ) + def pytest_runtest_call(): """ @@ -30,7 +35,8 @@ def pytest_runtest_call(): # Allow user to play with the setup. tgen.mininet_cli() - pytest.exit('the topology executed successfully') + pytest.exit("the topology executed successfully") + def pytest_assertrepr_compare(op, left, right): """ @@ -44,17 +50,19 @@ def pytest_assertrepr_compare(op, left, right): return json_result.errors + def pytest_configure(config): "Assert that the environment is correctly configured." global topology_only if not diagnose_env(): - pytest.exit('enviroment has errors, please read the logs') + pytest.exit("enviroment has errors, please read the logs") - if config.getoption('--topology-only'): + if config.getoption("--topology-only"): topology_only = True + def pytest_runtest_makereport(item, call): "Log all assert messages to default logger with error level" # Nothing happened @@ -65,18 +73,22 @@ def pytest_runtest_makereport(item, call): modname = parent.module.__name__ # Treat skips as non errors - if call.excinfo.typename != 'AssertionError': - logger.info('assert skipped at "{}/{}": {}'.format( - modname, item.name, call.excinfo.value)) + if call.excinfo.typename != "AssertionError": + logger.info( + 'assert skipped at "{}/{}": {}'.format( + modname, item.name, call.excinfo.value + ) + ) return # Handle assert failures parent._previousfailed = item - logger.error('assert failed at "{}/{}": {}'.format( - modname, item.name, call.excinfo.value)) + logger.error( + 'assert failed at "{}/{}": {}'.format(modname, item.name, call.excinfo.value) + ) # (topogen) Set topology error to avoid advancing in the test. tgen = get_topogen() if tgen is not None: # This will cause topogen to report error on `routers_have_failure`. - tgen.set_error('{}/{}'.format(modname, item.name)) + tgen.set_error("{}/{}".format(modname, item.name)) |
