pytest: don't invoke the pcap test every session.
What changed, and why it matters
This commit is a minor test-suite cleanup. It moves a check for packet-capture tools (dumpcap/tshark) so it only runs when a specific test actually needs it, instead of running once for every test session. There is no security issue here.
No action required. This is a benign test infrastructure change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change removes a session-scoped pytest fixture have_pcap_tools and inlines its dumpcap_usable() check into the tcp_capture fixture. This avoids invoking the pcap capability check on every test session and only runs it when the tcp_capture fixture is used. The functional behavior is identical: tests requiring tcp_capture still skip if pcap tools are unavailable. This is purely a test infrastructure optimization.
Changed components
tests/fixtures.pyInspect captured patch +4 / −7
diff --git a/tests/fixtures.py b/tests/fixtures.py
index 7ff7e26d..186d8723 100644
--- a/tests/fixtures.py
+++ b/tests/fixtures.py
@@ -119,12 +119,6 @@ def dumpcap_usable():
return False
-@pytest.fixture(scope="session")
-def have_pcap_tools():
- if not dumpcap_usable():
- pytest.skip("dumpcap/tshark not available or insufficient privileges")
-
-
class TcpCapture:
def __init__(self, tmpdir):
self.tmpdir = Path(tmpdir)
@@ -179,7 +173,7 @@ class TcpCapture:
@pytest.fixture
-def tcp_capture(have_pcap_tools, tmp_path):
+def tcp_capture(tmp_path):
# You will need permissions. Most distributions have a group which has
# permissions to use dumpcap:
# $ ls -l /usr/bin/dumpcap
@@ -187,6 +181,9 @@ def tcp_capture(have_pcap_tools, tmp_path):
# $ getcap /usr/bin/dumpcap
# /usr/bin/dumpcap cap_net_admin,cap_net_raw=eip
# So you just need to be in the wireshark group.
+ if not dumpcap_usable():
+ pytest.skip("dumpcap/tshark not available or insufficient privileges")
+
cap = TcpCapture(tmp_path)
yield cap
cap.stop()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.