aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2026-05-01 23:06:35 +0000
committerAlan Somers <asomers@FreeBSD.org>2026-08-05 02:18:14 +0000
commitc3be3a784c2b16b18ac8322dbf7863587f278bb9 (patch)
tree6f9b1aed8f81817d098fc467d7e05d46ea3a7a26
parenta4ebad0c202f5c2d08381d2ac732729cd386388f (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 Reviewed by: maxim Differential Revision: https://reviews.freebsd.org/D56765 (cherry picked from commit 3e845b1090565912375c5578cf0399d27b7fa70c)
-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 60ddd3d751bf..88164c2ab816 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):