aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2026-05-01 23:06:35 +0000
committerAlan Somers <asomers@FreeBSD.org>2026-05-02 15:20:16 +0000
commit3e845b1090565912375c5578cf0399d27b7fa70c (patch)
tree8081d4fe843921ee78902fbba6a954ef5170bffb
parent9f98195ff615417f7af875b65cdaf220239206db (diff)
ping: fix listing test cases when scapy is not installed
The ATF-python test program was attempting to list test cases that require scapy. But it attempted to import the scapy module before the test cases had been listed, resulting in an ImportError that kyua interpreted as a test program crash. Fix this behavior by handling that ImportError well enough to list test cases, but not run them. If scapy isn't present, Kyua will refuse to run the test cases. But it needs to be able to list them in order to know to skip them. Sponsored by: ConnectWise MFC after: 2 weeks Reviewed by: maxim Differential Revision: https://reviews.freebsd.org/D56765
-rw-r--r--sbin/ping/tests/test_ping.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/sbin/ping/tests/test_ping.py b/sbin/ping/tests/test_ping.py
index 3f9a3aecf924..fdf9c875329c 100644
--- a/sbin/ping/tests/test_ping.py
+++ b/sbin/ping/tests/test_ping.py
@@ -12,7 +12,31 @@ from typing import List
from typing import Optional
logging.getLogger("scapy").setLevel(logging.CRITICAL)
-import scapy.all as sc
+try:
+ import scapy.all as sc
+except ImportError as e:
+ # Fake scapy well enough to be able to list test cases
+ from types import SimpleNamespace
+ sc = SimpleNamespace(
+ scapy=SimpleNamespace(
+ fields=SimpleNamespace(
+ SourceIPField=0,
+ ByteEnumField=0,
+ MultiEnumField=0,
+ BitField=0,
+ FlagsField=0,
+ ByteField=0,
+ IPField=0,
+ ShortField=0,
+ ),
+ layers=SimpleNamespace(
+ inet=SimpleNamespace(
+ DestIPField=0,
+ ICMPTimeStampField=0,
+ )
+ )
+ )
+ )
def build_response_packet(echo, ip, icmp, oip_ihl, special):