From 54d7e96a72e5871792b1e0c1c29f6fd1ac0743c0 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 15 Oct 2018 16:07:30 +0200 Subject: test: make it possible to use pytest-style test fixtures Currently all binaries must be available or no tests will be executed. This is inconvenient if you just want to test a single binary (e.g. text2pcap) without having to build epan. The problem is essentially that tests lack dependency annotations. To solve this problem, add the required dependencies as parameters to each test (so-called 'fixtures' in pytest). Skip a test if a binary (such as tshark) is unavailable. As a demonstration, suite_dissection.py is converted. Over time, tests should no longer depend on config.py due to explicit dependencies fixtures (listed in fixtures_ws.py). Since the unittest module does not support such dependency injections, create a small glue for use with pytest and an (incomplete) emulation layer for use with test.py. Tested with pytest 3.8.2 + Python 3.7.0 and pytest 3.0.3 + Python 3.4.3. Python 2.7 is not supported and will fail. Test commands: ~/wireshark/test/test.py -p ~/build/run WS_BIN_PATH=~/build/run pytest ~/wireshark/test -ra Change-Id: I6dc8c28f5c8b7bbc8f4c04838e9bf085cd22eb0b Ping-Bug: 14949 Reviewed-on: https://code.wireshark.org/review/30220 Tested-by: Petri Dish Buildbot Petri-Dish: Peter Wu Reviewed-by: Anders Broman --- test/conftest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/conftest.py') diff --git a/test/conftest.py b/test/conftest.py index eff63dadaa..a09e86c485 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -10,9 +10,9 @@ import os import sys +import fixtures import config - # XXX remove globals in config and create py.test-specific fixtures try: _program_path = os.environ['WS_BIN_PATH'] @@ -32,3 +32,7 @@ def pytest_collection_modifyitems(items): if name not in suites: suites.append(name) config.all_groups = list(sorted(suites)) + +# Must enable pytest before importing fixtures_ws. +fixtures.enable_pytest() +from fixtures_ws import * -- cgit v1.2.3