summaryrefslogtreecommitdiffstats
path: root/tests/topotests/munet/testing
diff options
context:
space:
mode:
Diffstat (limited to 'tests/topotests/munet/testing')
-rw-r--r--tests/topotests/munet/testing/fixtures.py36
-rw-r--r--tests/topotests/munet/testing/hooks.py93
2 files changed, 32 insertions, 97 deletions
diff --git a/tests/topotests/munet/testing/fixtures.py b/tests/topotests/munet/testing/fixtures.py
index 3c6d946..3c6ddf9 100644
--- a/tests/topotests/munet/testing/fixtures.py
+++ b/tests/topotests/munet/testing/fixtures.py
@@ -25,7 +25,6 @@ from ..base import BaseMunet
from ..base import Bridge
from ..base import get_event_loop
from ..cleanup import cleanup_current
-from ..cleanup import cleanup_previous
from ..native import L3NodeMixin
from ..parser import async_build_topology
from ..parser import get_config
@@ -130,9 +129,12 @@ def session_autouse():
else:
is_worker = True
- if not is_worker:
- # This is unfriendly to multi-instance
- cleanup_previous()
+ # We dont want to kill all munet and we don't have the rundir here yet
+ # This was more useful back when we used to leave processes around a lot
+ # more.
+ # if not is_worker:
+ # # This is unfriendly to multi-instance
+ # cleanup_previous()
# We never pop as we want to keep logging
_push_log_handler("session", "/tmp/unet-test/pytest-session.log")
@@ -150,8 +152,9 @@ def session_autouse():
@pytest.fixture(autouse=True, scope="module")
def module_autouse(request):
- logpath = get_test_logdir(request.node.name, True)
- logpath = os.path.join("/tmp/unet-test", logpath, "pytest-exec.log")
+ root_path = os.environ.get("MUNET_RUNDIR", "/tmp/unet-test")
+ logpath = get_test_logdir(request.node.nodeid, True)
+ logpath = os.path.join(root_path, logpath, "pytest-exec.log")
with log_handler("module", logpath):
sdir = os.path.dirname(os.path.realpath(request.fspath))
with chdir(sdir, "module autouse fixture"):
@@ -161,7 +164,7 @@ def module_autouse(request):
raise Exception("Base Munet was not cleaned up/deleted")
-@pytest.fixture(scope="module")
+@pytest.fixture(scope="session")
def event_loop():
"""Create an instance of the default event loop for the session."""
loop = get_event_loop()
@@ -174,7 +177,8 @@ def event_loop():
@pytest.fixture(scope="module")
def rundir_module():
- d = os.path.join("/tmp/unet-test", get_test_logdir(module=True))
+ root_path = os.environ.get("MUNET_RUNDIR", "/tmp/unet-test")
+ d = os.path.join(root_path, get_test_logdir(module=True))
logging.debug("conftest: test module rundir %s", d)
return d
@@ -213,18 +217,14 @@ async def _unet_impl(
param,
exc_info=True,
)
- pytest.skip(
- f"unet fixture: unet build failed: {error}", allow_module_level=True
- )
- raise
+ pytest.fail(f"unet fixture: unet build failed: {error}")
try:
tasks = await _unet.run()
except Exception as error:
logging.debug("unet fixture: unet run failed: %s", error, exc_info=True)
await _unet.async_delete()
- pytest.skip(f"unet fixture: unet run failed: {error}", allow_module_level=True)
- raise
+ pytest.fail(f"unet fixture: unet run failed: {error}")
logging.debug("unet fixture: containers running")
@@ -379,7 +379,8 @@ async def astepf(pytestconfig):
@pytest.fixture(scope="function")
def rundir():
- d = os.path.join("/tmp/unet-test", get_test_logdir(module=False))
+ root_path = os.environ.get("MUNET_RUNDIR", "/tmp/unet-test")
+ d = os.path.join(root_path, get_test_logdir(module=False))
logging.debug("conftest: test function rundir %s", d)
return d
@@ -387,9 +388,8 @@ def rundir():
# Configure logging
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_setup(item):
- d = os.path.join(
- "/tmp/unet-test", get_test_logdir(nodeid=item.nodeid, module=False)
- )
+ root_path = os.environ.get("MUNET_RUNDIR", "/tmp/unet-test")
+ d = os.path.join(root_path, get_test_logdir(nodeid=item.nodeid, module=False))
config = item.config
logging_plugin = config.pluginmanager.get_plugin("logging-plugin")
filename = Path(d, "pytest-exec.log")
diff --git a/tests/topotests/munet/testing/hooks.py b/tests/topotests/munet/testing/hooks.py
index 985eef9..f6f2115 100644
--- a/tests/topotests/munet/testing/hooks.py
+++ b/tests/topotests/munet/testing/hooks.py
@@ -18,6 +18,7 @@ import traceback
import pytest
+from ..args import add_testing_args
from ..base import BaseMunet # pylint: disable=import-error
from ..cli import cli # pylint: disable=import-error
from .util import pause_test
@@ -29,85 +30,7 @@ from .util import pause_test
def pytest_addoption(parser):
- parser.addoption(
- "--cli-on-error",
- action="store_true",
- help="CLI on test failure",
- )
-
- parser.addoption(
- "--coverage",
- action="store_true",
- help="Enable coverage gathering if supported",
- )
-
- parser.addoption(
- "--gdb",
- default="",
- metavar="HOST[,HOST...]",
- help="Comma-separated list of nodes to launch gdb on, or 'all'",
- )
- parser.addoption(
- "--gdb-breakpoints",
- default="",
- metavar="BREAKPOINT[,BREAKPOINT...]",
- help="Comma-separated list of breakpoints",
- )
- parser.addoption(
- "--gdb-use-emacs",
- action="store_true",
- help="Use emacsclient to run gdb instead of a shell",
- )
-
- parser.addoption(
- "--pcap",
- default="",
- metavar="NET[,NET...]",
- help="Comma-separated list of networks to capture packets on, or 'all'",
- )
-
- parser.addoption(
- "--pause",
- action="store_true",
- help="Pause after each test",
- )
- parser.addoption(
- "--pause-at-end",
- action="store_true",
- help="Pause before taking munet down",
- )
- parser.addoption(
- "--pause-on-error",
- action="store_true",
- help="Pause after (disables default when --shell or -vtysh given)",
- )
- parser.addoption(
- "--no-pause-on-error",
- dest="pause_on_error",
- action="store_false",
- help="Do not pause after (disables default when --shell or -vtysh given)",
- )
-
- parser.addoption(
- "--shell",
- default="",
- metavar="NODE[,NODE...]",
- help="Comma-separated list of nodes to spawn shell on, or 'all'",
- )
-
- parser.addoption(
- "--stdout",
- default="",
- metavar="NODE[,NODE...]",
- help="Comma-separated list of nodes to open tail-f stdout window on, or 'all'",
- )
-
- parser.addoption(
- "--stderr",
- default="",
- metavar="NODE[,NODE...]",
- help="Comma-separated list of nodes to open tail-f stderr window on, or 'all'",
- )
+ add_testing_args(parser.addoption)
def pytest_configure(config):
@@ -146,6 +69,18 @@ def pytest_configure(config):
elif b and not is_xdist and not have_windows:
pytest.exit(f"{winopt} use requires byobu/TMUX/SCREEN/XTerm")
+ cli_pause = (
+ config.getoption("--cli-on-error")
+ or config.getoption("--pause")
+ or config.getoption("--pause-at-end")
+ or config.getoption("--pause-on-error")
+ )
+ if config.getoption("--capture") == "fd" and cli_pause:
+ pytest.exit(
+ "CLI is not compatible with `--capture=fd`, "
+ "please run again with `-s` or other `--capture` value"
+ )
+
def pytest_runtest_makereport(item, call):
"""Pause or invoke CLI as directed by config."""