Define the anonymizer test plugin at module level

Windows spawns meter processes instead of forking them, so plugin instances
must be pickled to reach them. The plugin was defined inside the test
function, which cannot be pickled, and the Windows job failed with

  AttributeError: Can't pickle local object
  'NFStreamTest.test_anonymize_absent_values.<locals>.MixedValues'

Linux and macOS fork, so the plugin was inherited rather than pickled and the
test passed there. The failure was also masked at first because the Windows
jobs were failing earlier, at the Npcap download, and never reached the tests.

Moving the class to module level makes it picklable, matching how the other
plugins used in the suite are defined.
This commit is contained in:
Adrian Pekar 2026-08-01 15:45:20 +02:00
parent c776ef755f
commit 427ba6e151

View file

@ -21,6 +21,17 @@ from nfstream import NFPlugin, NFStreamer
from nfstream.plugins import SPLT, DHCP, FlowSlicer, MDNS
class AnonymizerMixedValues(NFPlugin):
"""Must remain module-level because Windows spawn pickles plugins."""
def on_init(self, packet, flow):
flow.udps.absent = ""
flow.udps.populated = "value"
flow.udps.zero = 0
flow.udps.false = False
flow.udps.array = np.zeros(3)
def get_files_list(path):
files = []
for r, d, f in os.walk(path):
@ -918,20 +929,10 @@ class NFStreamTest(object):
"\n----------------------------------------------------------------------"
)
class MixedValues(NFPlugin):
"""Produces an absent value alongside values that only look absent."""
def on_init(self, packet, flow):
flow.udps.absent = ""
flow.udps.populated = "value"
flow.udps.zero = 0
flow.udps.false = False
flow.udps.array = np.zeros(3)
df = NFStreamer(
source=os.path.join("tests", "pcaps", "google_ssl.pcap"),
n_meters=1,
udps=MixedValues(),
udps=AnonymizerMixedValues(),
).to_pandas(
columns_to_anonymize=[
"udps.absent",