test: convert some more tests to use fixtures
authorPeter Wu <peter@lekensteyn.nl>
Tue, 13 Nov 2018 01:17:33 +0000 (02:17 +0100)
committerAnders Broman <a.broman58@gmail.com>
Wed, 14 Nov 2018 05:00:37 +0000 (05:00 +0000)
Continue the conversion from use of globals (the config module) to
fixtures. If a program (like wmem_test or tshark) is unavailable, it
will be skipped now rather than failing the test.

The general conversion pattern is:
- Decorate each class with `@fixtures.uses_fixtures` and (for tests that
  run tshark) `@fixtures.mark_usefixtures('test_env')`.
- Convert all `config.cmd_*` to `cmd_*` and add an argument.
- Convert all `config.*_dir` to `dirs.*_dir` and add an argument.
- Convert users of `os.path.join(dirs.capture_file, ...)` to use a new
  'capture_file' fixture to reduce boilerplate code. Inline variables if
  possible (this conversion was done in an automated way using regexes).

Some other changes: tests that do not require a test environment (like
wmem_test) will use 'base_env' which avoids copying config files,
`env=config.test_env` got removed since this is the default. Some test
classes in suite_clopts were combined. Removed unused imports.

Change-Id: Id5480ffaee7d8d56cf2cb3189a38ae9afa7605a1
Reviewed-on: https://code.wireshark.org/review/30591
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
test/fixtures_ws.py
test/suite_clopts.py
test/suite_decryption.py
test/suite_dissection.py
test/suite_fileformats.py
test/suite_follow.py
test/suite_io.py
test/suite_mergecap.py
test/suite_sharkd.py
test/suite_unittests.py
test/suite_wslua.py

index 29b119ba67456fc1f5704f1258956220e2f5840a..dce633e305c961a0f1da2806b8bcbfca689a1b96 100644 (file)
@@ -114,6 +114,14 @@ def dirs():
     )
 
 
+@fixtures.fixture(scope='session')
+def capture_file(dirs):
+    '''Returns the path to a capture file.'''
+    def resolver(filename):
+        return os.path.join(dirs.capture_dir, filename)
+    return resolver
+
+
 @fixtures.fixture
 def home_path():
     '''Per-test home directory, removed when finished.'''
index 98981ad8caf1cbf6afb7f36b2816ee39be6a4bd9..9be3e13079512899b4b4024093381a82c65e03ae 100644 (file)
 '''Command line option tests'''
 
 import config
-import os.path
 import subprocess
 import subprocesstest
 import unittest
+import fixtures
 
 #glossaries = ('fields', 'protocols', 'values', 'decodes', 'defaultprefs', 'currentprefs')
 
 glossaries = ('decodes', 'values')
 testout_pcap = 'testout.pcap'
 
-class case_dumpcap_invalid_chars(subprocesstest.SubprocessTestCase):
+
+@fixtures.uses_fixtures
+class case_dumpcap_options(subprocesstest.SubprocessTestCase):
     # XXX Should we generate individual test functions instead of looping?
-    def test_dumpcap_invalid_chars(self):
+    def test_dumpcap_invalid_chars(self, cmd_dumpcap, base_env):
         '''Invalid dumpcap parameters'''
         for char_arg in 'CEFGHJKNOQRTUVWXYejloxz':
-            self.assertRun((config.cmd_dumpcap, '-' + char_arg),
+            self.assertRun((cmd_dumpcap, '-' + char_arg), env=base_env,
                            expected_return=self.exit_command_line)
 
-
-class case_dumpcap_valid_chars(subprocesstest.SubprocessTestCase):
     # XXX Should we generate individual test functions instead of looping?
-    def test_dumpcap_valid_chars(self):
+    def test_dumpcap_valid_chars(self, cmd_dumpcap, base_env):
         for char_arg in 'hv':
-            self.assertRun((config.cmd_dumpcap, '-' + char_arg))
+            self.assertRun((cmd_dumpcap, '-' + char_arg), env=base_env)
 
-
-class case_dumpcap_invalid_interface_chars(subprocesstest.SubprocessTestCase):
     # XXX Should we generate individual test functions instead of looping?
-    def test_dumpcap_interface_chars(self):
+    def test_dumpcap_interface_chars(self, cmd_dumpcap, base_env):
         '''Valid dumpcap parameters requiring capture permissions'''
         valid_returns = [self.exit_ok, self.exit_error]
         for char_arg in 'DL':
-            process = self.runProcess((config.cmd_dumpcap, '-' + char_arg))
+            process = self.runProcess((cmd_dumpcap, '-' + char_arg), env=base_env)
             self.assertIn(process.returncode, valid_returns)
 
 
+@fixtures.uses_fixtures
 class case_dumpcap_capture_clopts(subprocesstest.SubprocessTestCase):
-    def test_dumpcap_invalid_capfilter(self):
+    def test_dumpcap_invalid_capfilter(self, cmd_dumpcap, base_env):
         '''Invalid capture filter'''
         if not config.canCapture():
             self.skipTest('Test requires capture privileges and an interface.')
         invalid_filter = '__invalid_protocol'
         # $DUMPCAP -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        self.runProcess((config.cmd_dumpcap, '-f', invalid_filter, '-w', testout_file ))
+        self.runProcess((cmd_dumpcap, '-f', invalid_filter, '-w', testout_file), env=base_env)
         self.assertTrue(self.grepOutput('Invalid capture filter "' + invalid_filter + '" for interface'))
 
-    def test_dumpcap_invalid_interface_name(self):
+    def test_dumpcap_invalid_interface_name(self, cmd_dumpcap, base_env):
         '''Invalid capture interface name'''
         if not config.canCapture():
             self.skipTest('Test requires capture privileges and an interface.')
         invalid_interface = '__invalid_interface'
         # $DUMPCAP -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        self.runProcess((config.cmd_dumpcap, '-i', invalid_interface, '-w', testout_file))
+        self.runProcess((cmd_dumpcap, '-i', invalid_interface, '-w', testout_file), env=base_env)
         self.assertTrue(self.grepOutput('The capture session could not be initiated'))
 
-    def test_dumpcap_invalid_interface_index(self):
+    def test_dumpcap_invalid_interface_index(self, cmd_dumpcap, base_env):
         '''Invalid capture interface index'''
         if not config.canCapture():
             self.skipTest('Test requires capture privileges and an interface.')
         invalid_index = '0'
         # $DUMPCAP -i 0 -w './testout.pcap' > ./testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        self.runProcess((config.cmd_dumpcap, '-i', invalid_index, '-w', testout_file))
+        self.runProcess((cmd_dumpcap, '-i', invalid_index, '-w', testout_file), env=base_env)
         self.assertTrue(self.grepOutput('There is no interface with that adapter index'))
 
 
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_basic_clopts(subprocesstest.SubprocessTestCase):
-    def test_existing_file(self):
+    def test_existing_file(self, cmd_tshark, capture_file):
         # $TSHARK -r "${CAPTURE_DIR}dhcp.pcap" > ./testout.txt 2>&1
-        cap_file = os.path.join(config.capture_dir, 'dhcp.pcap')
-        self.assertRun((config.cmd_tshark, '-r', cap_file))
+        self.assertRun((cmd_tshark, '-r', capture_file('dhcp.pcap')))
 
-    def test_nonexistent_file(self):
+    def test_nonexistent_file(self, cmd_tshark, capture_file):
         # $TSHARK - r ThisFileDontExist.pcap > ./testout.txt 2 > &1
-        cap_file = os.path.join(config.capture_dir, '__ceci_nest_pas_une.pcap')
-        self.assertRun((config.cmd_tshark, '-r', cap_file),
+        self.assertRun((cmd_tshark, '-r', capture_file('__ceci_nest_pas_une.pcap')),
                        expected_return=self.exit_error)
 
 
-class case_tshark_invalid_chars(subprocesstest.SubprocessTestCase):
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
+class case_tshark_options(subprocesstest.SubprocessTestCase):
     # XXX Should we generate individual test functions instead of looping?
-    def test_tshark_invalid_chars(self):
+    def test_tshark_invalid_chars(self, cmd_tshark):
         '''Invalid tshark parameters'''
         for char_arg in 'ABCEFHJKMNORTUWXYZabcdefijkmorstuwyz':
-            self.assertRun((config.cmd_tshark, '-' + char_arg),
+            self.assertRun((cmd_tshark, '-' + char_arg),
                            expected_return=self.exit_command_line)
 
-
-class case_tshark_valid_chars(subprocesstest.SubprocessTestCase):
     # XXX Should we generate individual test functions instead of looping?
-    def test_tshark_valid_chars(self):
+    def test_tshark_valid_chars(self, cmd_tshark):
         for char_arg in 'Ghv':
-            self.assertRun((config.cmd_tshark, '-' + char_arg))
+            self.assertRun((cmd_tshark, '-' + char_arg))
 
-
-class case_tshark_invalid_interface_chars(subprocesstest.SubprocessTestCase):
     # XXX Should we generate individual test functions instead of looping?
-    def test_tshark_interface_chars(self):
+    def test_tshark_interface_chars(self, cmd_tshark):
         '''Valid tshark parameters requiring capture permissions'''
         valid_returns = [self.exit_ok, self.exit_error]
         for char_arg in 'DL':
-            process = self.runProcess((config.cmd_tshark, '-' + char_arg))
+            process = self.runProcess((cmd_tshark, '-' + char_arg))
             self.assertIn(process.returncode, valid_returns)
 
 
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_tshark_capture_clopts(subprocesstest.SubprocessTestCase):
-    def test_tshark_invalid_capfilter(self):
+    def test_tshark_invalid_capfilter(self, cmd_tshark):
         '''Invalid capture filter'''
         if not config.canCapture():
             self.skipTest('Test requires capture privileges and an interface.')
         invalid_filter = '__invalid_protocol'
         # $TSHARK -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        self.runProcess((config.cmd_tshark, '-f', invalid_filter, '-w', testout_file ))
+        self.runProcess((cmd_tshark, '-f', invalid_filter, '-w', testout_file ))
         self.assertTrue(self.grepOutput('Invalid capture filter "' + invalid_filter + '" for interface'))
 
-    def test_tshark_invalid_interface_name(self):
+    def test_tshark_invalid_interface_name(self, cmd_tshark):
         '''Invalid capture interface name'''
         if not config.canCapture():
             self.skipTest('Test requires capture privileges and an interface.')
         invalid_interface = '__invalid_interface'
         # $TSHARK -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        self.runProcess((config.cmd_tshark, '-i', invalid_interface, '-w', testout_file))
+        self.runProcess((cmd_tshark, '-i', invalid_interface, '-w', testout_file))
         self.assertTrue(self.grepOutput('The capture session could not be initiated'))
 
-    def test_tshark_invalid_interface_index(self):
+    def test_tshark_invalid_interface_index(self, cmd_tshark):
         '''Invalid capture interface index'''
         if not config.canCapture():
             self.skipTest('Test requires capture privileges and an interface.')
         invalid_index = '0'
         # $TSHARK -i 0 -w './testout.pcap' > ./testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        self.runProcess((config.cmd_tshark, '-i', invalid_index, '-w', testout_file))
+        self.runProcess((cmd_tshark, '-i', invalid_index, '-w', testout_file))
         self.assertTrue(self.grepOutput('There is no interface with that adapter index'))
 
 
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_tshark_name_resolution_clopts(subprocesstest.SubprocessTestCase):
-    def test_tshark_valid_name_resolution(self):
+    def test_tshark_valid_name_resolution(self, cmd_tshark):
         if not config.canCapture():
             self.skipTest('Test requires capture privileges and an interface.')
         # $TSHARK -N mnNtdv -a duration:1 > ./testout.txt 2>&1
-        self.assertRun((config.cmd_tshark, '-N', 'mnNtdv', '-a', 'duration: 1'))
+        self.assertRun((cmd_tshark, '-N', 'mnNtdv', '-a', 'duration: 1'))
 
     # XXX Add invalid name resolution.
 
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_tshark_unicode_clopts(subprocesstest.SubprocessTestCase):
-    def test_tshark_unicode_display_filter(self):
+    def test_tshark_unicode_display_filter(self, cmd_tshark, capture_file):
         '''Unicode (UTF-8) display filter'''
-        cap_file = os.path.join(config.capture_dir, 'http.pcap')
-        self.runProcess((config.cmd_tshark, '-r', cap_file, '-Y', 'tcp.flags.str == "·······AP···"'))
+        self.runProcess((cmd_tshark, '-r', capture_file('http.pcap'), '-Y', 'tcp.flags.str == "·······AP···"'))
         self.assertTrue(self.grepOutput('HEAD.*/v4/iuident.cab'))
 
 
+@fixtures.uses_fixtures
 class case_tshark_dump_glossaries(subprocesstest.SubprocessTestCase):
-    def test_tshark_dump_glossary(self):
+    def test_tshark_dump_glossary(self, cmd_tshark, base_env):
         for glossary in glossaries:
             try:
                 self.log_fd.truncate()
             except:
                 pass
-            self.assertRun((config.cmd_tshark, '-G', glossary))
+            self.assertRun((cmd_tshark, '-G', glossary), env=base_env)
             self.assertEqual(self.countOutput(count_stdout=False, count_stderr=True), 0, 'Found error output while printing glossary ' + glossary)
 
-    def test_tshark_glossary_valid_utf8(self):
+    def test_tshark_glossary_valid_utf8(self, cmd_tshark, base_env):
         for glossary in glossaries:
-            env = config.baseEnv()
+            env = base_env
             env['LANG'] = 'en_US.UTF-8'
-            g_contents = subprocess.check_output((config.cmd_tshark, '-G', glossary), env=env, stderr=subprocess.PIPE)
+            g_contents = subprocess.check_output((cmd_tshark, '-G', glossary), env=env, stderr=subprocess.PIPE)
             decoded = True
             try:
                 g_contents.decode('UTF-8')
@@ -188,82 +191,79 @@ class case_tshark_dump_glossaries(subprocesstest.SubprocessTestCase):
                 decoded = False
             self.assertTrue(decoded, '{} is not valid UTF-8'.format(glossary))
 
-    def test_tshark_glossary_plugin_count(self):
-        self.runProcess((config.cmd_tshark, '-G', 'plugins'), env=config.baseEnv())
+    def test_tshark_glossary_plugin_count(self, cmd_tshark, base_env):
+        self.runProcess((cmd_tshark, '-G', 'plugins'), env=base_env)
         self.assertGreaterEqual(self.countOutput('dissector'), 10, 'Fewer than 10 dissector plugins found')
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_tshark_z_expert(subprocesstest.SubprocessTestCase):
-    def test_tshark_z_expert_all(self):
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert',
-            '-r', os.path.join(config.capture_dir, 'http-ooo.pcap')))
+    def test_tshark_z_expert_all(self, cmd_tshark, capture_file):
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert',
+            '-r', capture_file('http-ooo.pcap')))
         self.assertTrue(self.grepOutput('Errors'))
         self.assertTrue(self.grepOutput('Warns'))
         self.assertTrue(self.grepOutput('Chats'))
 
-    def test_tshark_z_expert_error(self):
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,error',
-            '-r', os.path.join(config.capture_dir, 'http-ooo.pcap')))
+    def test_tshark_z_expert_error(self, cmd_tshark, capture_file):
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,error',
+            '-r', capture_file('http-ooo.pcap')))
         self.assertTrue(self.grepOutput('Errors'))
         self.assertFalse(self.grepOutput('Warns'))
         self.assertFalse(self.grepOutput('Chats'))
 
-    def test_tshark_z_expert_warn(self):
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,warn',
-            '-r', os.path.join(config.capture_dir, 'http-ooo.pcap')))
+    def test_tshark_z_expert_warn(self, cmd_tshark, capture_file):
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,warn',
+            '-r', capture_file('http-ooo.pcap')))
         self.assertTrue(self.grepOutput('Errors'))
         self.assertTrue(self.grepOutput('Warns'))
         self.assertFalse(self.grepOutput('Chats'))
 
-    def test_tshark_z_expert_note(self):
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,note',
-            '-r', os.path.join(config.capture_dir, 'http2-data-reassembly.pcap')))
+    def test_tshark_z_expert_note(self, cmd_tshark, capture_file):
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,note',
+            '-r', capture_file('http2-data-reassembly.pcap')))
         self.assertTrue(self.grepOutput('Warns'))
         self.assertTrue(self.grepOutput('Notes'))
         self.assertFalse(self.grepOutput('Chats'))
 
-    def test_tshark_z_expert_chat(self):
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,chat',
-            '-r', os.path.join(config.capture_dir, 'http-ooo.pcap')))
+    def test_tshark_z_expert_chat(self, cmd_tshark, capture_file):
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,chat',
+            '-r', capture_file('http-ooo.pcap')))
         self.assertTrue(self.grepOutput('Errors'))
         self.assertTrue(self.grepOutput('Warns'))
         self.assertTrue(self.grepOutput('Chats'))
 
-    def test_tshark_z_expert_comment(self):
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,comment',
-            '-r', os.path.join(config.capture_dir, 'sip.pcapng')))
+    def test_tshark_z_expert_comment(self, cmd_tshark, capture_file):
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,comment',
+            '-r', capture_file('sip.pcapng')))
         self.assertTrue(self.grepOutput('Notes'))
         self.assertTrue(self.grepOutput('Comments'))
 
-    def test_tshark_z_expert_invalid_filter(self):
+    def test_tshark_z_expert_invalid_filter(self, cmd_tshark, capture_file):
         invalid_filter = '__invalid_protocol'
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,' + invalid_filter,
-            '-r', os.path.join(config.capture_dir, 'http-ooo.pcap')),
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,' + invalid_filter,
+            '-r', capture_file('http-ooo.pcap')),
             expected_return=self.exit_command_line)
         self.assertTrue(self.grepOutput('Filter "' + invalid_filter + '" is invalid'))
 
-    def test_tshark_z_expert_error_invalid_filter(self):
+    def test_tshark_z_expert_error_invalid_filter(self, cmd_tshark, capture_file):
         invalid_filter = '__invalid_protocol'
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,error,' + invalid_filter,
-            '-r', os.path.join(config.capture_dir, 'http-ooo.pcap')),
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,error,' + invalid_filter,
+            '-r', capture_file('http-ooo.pcap')),
             expected_return=self.exit_command_line)
         self.assertTrue(self.grepOutput('Filter "' + invalid_filter + '" is invalid'))
 
-    def test_tshark_z_expert_filter(self):
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,udp', #udp is a filter
-            '-r', os.path.join(config.capture_dir, 'http-ooo.pcap')))
+    def test_tshark_z_expert_filter(self, cmd_tshark, capture_file):
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,udp',  # udp is a filter
+            '-r', capture_file('http-ooo.pcap')))
         self.assertFalse(self.grepOutput('Errors'))
         self.assertFalse(self.grepOutput('Warns'))
         self.assertFalse(self.grepOutput('Chats'))
 
-    def test_tshark_z_expert_error_filter(self):
-        self.assertRun((config.cmd_tshark, '-q', '-z', 'expert,error,udp', #udp is a filter
-            '-r', os.path.join(config.capture_dir, 'http-ooo.pcap')))
+    def test_tshark_z_expert_error_filter(self, cmd_tshark, capture_file):
+        self.assertRun((cmd_tshark, '-q', '-z', 'expert,error,udp',  # udp is a filter
+            '-r', capture_file('http-ooo.pcap')))
         self.assertFalse(self.grepOutput('Errors'))
         self.assertFalse(self.grepOutput('Warns'))
         self.assertFalse(self.grepOutput('Chats'))
-
-# Purposefully fail a test. Used for testing the test framework.
-# class case_fail_on_purpose(subprocesstest.SubprocessTestCase):
-#     def test_fail_on_purpose(self):
-#         self.runProcess(('echo', 'hello, world'))
-#         self.fail('Not implemented')
index 606c89b894a1f552aa3e9ae2ad6c4c3650c883c1..6e250c8a8022376438a482eaf8becd923ec54546 100644 (file)
 #
 '''Decryption tests'''
 
-import config
 import os.path
 import subprocesstest
 import unittest
+import fixtures
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_80211(subprocesstest.SubprocessTestCase):
-    def test_80211_wpa_psk(self):
+    def test_80211_wpa_psk(self, cmd_tshark, capture_file):
         '''IEEE 802.11 WPA PSK'''
         # https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=view&target=wpa-Induction.pcap
-        capture_file = os.path.join(config.capture_dir, 'wpa-Induction.pcap.gz')
-        self.runProcess((config.cmd_tshark,
+        self.runProcess((cmd_tshark,
                 '-o', 'wlan.enable_decryption: TRUE',
                 '-Tfields',
                 '-e', 'http.request.uri',
-                '-r', capture_file,
+                '-r', capture_file('wpa-Induction.pcap.gz'),
                 '-Y', 'http',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('favicon.ico'))
 
-    def test_80211_wpa_eap(self):
+    def test_80211_wpa_eap(self, cmd_tshark, capture_file):
         '''IEEE 802.11 WPA EAP (EAPOL Rekey)'''
         # Included in git sources test/captures/wpa-eap-tls.pcap.gz
-        capture_file = os.path.join(config.capture_dir, 'wpa-eap-tls.pcap.gz')
-        self.runProcess((config.cmd_tshark,
+        self.runProcess((cmd_tshark,
                 '-o', 'wlan.enable_decryption: TRUE',
-                '-r', capture_file,
+                '-r', capture_file('wpa-eap-tls.pcap.gz'),
                 '-Y', 'wlan.analysis.tk==7d9987daf5876249b6c773bf454a0da7',
-                ),
-            env=config.test_env)
+                ))
         self.assertTrue(self.grepOutput('Group Message'))
 
-    def test_80211_wpa_eapol_incomplete_rekeys(self):
+    def test_80211_wpa_eapol_incomplete_rekeys(self, cmd_tshark, capture_file):
         '''WPA decode with message1+2 only and secure bit set on message 2'''
         # Included in git sources test/captures/wpa-test-decode.pcap.gz
-        capture_file = os.path.join(config.capture_dir, 'wpa-test-decode.pcap.gz')
-        self.runProcess((config.cmd_tshark,
+        self.runProcess((cmd_tshark,
                 '-o', 'wlan.enable_decryption: TRUE',
-                '-r', capture_file,
+                '-r', capture_file('wpa-test-decode.pcap.gz'),
                 '-Y', 'icmp.resp_to == 4263',
-                ),
-            env=config.test_env)
+                ))
         self.assertTrue(self.grepOutput('Echo'))
 
-    def test_80211_wpa_psk_mfp(self):
+    def test_80211_wpa_psk_mfp(self, cmd_tshark, capture_file):
         '''WPA decode management frames with MFP enabled (802.11w)'''
         # Included in git sources test/captures/wpa-test-decode-mgmt.pcap.gz
-        capture_file = os.path.join(config.capture_dir, 'wpa-test-decode-mgmt.pcap.gz')
-        self.runProcess((config.cmd_tshark,
+        self.runProcess((cmd_tshark,
                 '-o', 'wlan.enable_decryption: TRUE',
-                '-r', capture_file,
+                '-r', capture_file('wpa-test-decode-mgmt.pcap.gz'),
                 '-Y', 'wlan.fixed.reason_code == 2 || wlan.fixed.category_code == 3',
-                ),
-            env=config.test_env)
+                ))
         self.assertEqual(self.countOutput('802.11.*SN=.*FN=.*Flags='), 3)
 
 
-    def test_80211_wpa_tdls(self):
+    def test_80211_wpa_tdls(self, cmd_tshark, capture_file, features):
         '''WPA decode traffic in a TDLS (Tunneled Direct-Link Setup) session (802.11z)'''
-        if not config.have_libgcrypt16:
+        if not features.have_libgcrypt16:
             self.skipTest('Requires GCrypt 1.6 or later.')
         # Included in git sources test/captures/wpa-test-decode-tdls.pcap.gz
-        capture_file = os.path.join(config.capture_dir, 'wpa-test-decode-tdls.pcap.gz')
-        self.runProcess((config.cmd_tshark,
+        self.runProcess((cmd_tshark,
                 #'-ouat:80211_keys:"wpa-pwd","12345678"',
                 '-o', 'wlan.enable_decryption: TRUE',
-                '-r', capture_file,
+                '-r', capture_file('wpa-test-decode-tdls.pcap.gz'),
                 '-Y', 'icmp',
-                ),
-            env=config.test_env)
+                ))
         self.assertEqual(self.countOutput('ICMP.*Echo .ping'), 2)
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_dtls(subprocesstest.SubprocessTestCase):
-    def test_dtls(self):
+    def test_dtls(self, cmd_tshark, capture_file):
         '''DTLS'''
         # https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=view&target=snakeoil.tgz
-        capture_file = os.path.join(config.capture_dir, 'snakeoil-dtls.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('snakeoil-dtls.pcap'),
                 '-Tfields',
                 '-e', 'data.data',
                 '-Y', 'data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('697420776f726b20210a'))
 
-    def test_dtls_psk_aes128ccm8(self):
+    def test_dtls_psk_aes128ccm8(self, cmd_tshark, capture_file):
         '''DTLS 1.2 with PSK, AES-128-CCM-8'''
-        capture_file = os.path.join(config.capture_dir, 'dtls12-aes128ccm8.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('dtls12-aes128ccm8.pcap'),
                 '-o', 'dtls.psk:ca19e028a8a372ad2d325f950fcaceed',
                 '-x'
-            ),
-            env=config.test_env)
+            ))
         dt_count = self.countOutput('Decrypted DTLS')
         wfm_count = self.countOutput('Works for me!.')
         self.assertTrue(dt_count == 7 and wfm_count == 2)
 
-    def test_dtls_udt(self):
+    def test_dtls_udt(self, cmd_tshark, dirs, capture_file):
         '''UDT over DTLS 1.2 with RSA key'''
-        capture_file = os.path.join(config.capture_dir, 'udt-dtls.pcapng.gz')
-        key_file = os.path.join(config.key_dir, 'udt-dtls.key')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        key_file = os.path.join(dirs.key_dir, 'udt-dtls.key')
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('udt-dtls.pcapng.gz'),
                 '-o', 'dtls.keys_list:0.0.0.0,0,data,{}'.format(key_file),
                 '-Y', 'dtls && udt.type==ack',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('UDT'))
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_tls(subprocesstest.SubprocessTestCase):
-    def test_tls(self):
+    def test_tls(self, cmd_tshark, capture_file):
         '''TLS using the server's private key'''
         # https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=view&target=snakeoil2_070531.tgz
-        capture_file = os.path.join(config.capture_dir, 'rsasnakeoil2.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('rsasnakeoil2.pcap'),
                 '-Tfields',
                 '-e', 'http.request.uri',
                 '-Y', 'http',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('favicon.ico'))
 
-    def test_tls_rsa_pq(self):
+    def test_tls_rsa_pq(self, cmd_tshark, dirs, capture_file):
         '''TLS using the server's private key with p < q
         (test whether libgcrypt is correctly called)'''
-        capture_file = os.path.join(config.capture_dir, 'rsa-p-lt-q.pcap')
-        key_file = os.path.join(config.key_dir, 'rsa-p-lt-q.key')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        key_file = os.path.join(dirs.key_dir, 'rsa-p-lt-q.key')
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('rsa-p-lt-q.pcap'),
                 '-o', 'tls.keys_list:0.0.0.0,443,http,{}'.format(key_file),
                 '-Tfields',
                 '-e', 'http.request.uri',
                 '-Y', 'http',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('/'))
 
-    def test_tls_with_password(self):
+    def test_tls_with_password(self, cmd_tshark, capture_file):
         '''TLS using the server's private key with password'''
-        capture_file = os.path.join(config.capture_dir, 'dmgr.pcapng')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('dmgr.pcapng'),
                 '-Tfields',
                 '-e', 'http.request.uri',
                 '-Y', 'http',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('unsecureLogon.jsp'))
 
-    def test_tls_master_secret(self):
+    def test_tls_master_secret(self, cmd_tshark, dirs, capture_file):
         '''TLS using the master secret and ssl.keylog_file preference aliasing'''
-        capture_file = os.path.join(config.capture_dir, 'dhe1.pcapng.gz')
-        key_file = os.path.join(config.key_dir, 'dhe1_keylog.dat')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        key_file = os.path.join(dirs.key_dir, 'dhe1_keylog.dat')
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('dhe1.pcapng.gz'),
                 '-o', 'ssl.keylog_file: {}'.format(key_file),
                 '-o', 'tls.desegment_ssl_application_data: FALSE',
                 '-o', 'http.tls.port: 443',
@@ -175,56 +161,48 @@ class case_decrypt_tls(subprocesstest.SubprocessTestCase):
                 '-e', 'http.request.uri',
                 '-e', 'http.request.version',
                 '-Y', 'http',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput(r'GET\s+/test\s+HTTP/1.0'))
 
-    def test_tls12_renegotiation(self):
+    def test_tls12_renegotiation(self, cmd_tshark, dirs, capture_file):
         '''TLS 1.2 with renegotiation'''
-        capture_file = os.path.join(config.capture_dir, 'tls-renegotiation.pcap')
-        key_file = os.path.join(config.key_dir, 'rsasnakeoil2.key')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        key_file = os.path.join(dirs.key_dir, 'rsasnakeoil2.key')
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('tls-renegotiation.pcap'),
                 '-o', 'tls.keys_list:0.0.0.0,4433,http,{}'.format(key_file),
                 '-Tfields',
                 '-e', 'http.content_length',
                 '-Y', 'http',
-            ),
-            env=config.test_env)
+            ))
         count_0 = self.countOutput('^0$')
         count_2151 = self.countOutput('^2151$')
         self.assertTrue(count_0 == 1 and count_2151 == 1)
 
-    def test_tls12_psk_aes128ccm(self):
+    def test_tls12_psk_aes128ccm(self, cmd_tshark, capture_file):
         '''TLS 1.2 with PSK, AES-128-CCM'''
-        capture_file = os.path.join(config.capture_dir, 'tls12-aes128ccm.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('tls12-aes128ccm.pcap'),
                 '-o', 'tls.psk:ca19e028a8a372ad2d325f950fcaceed',
                 '-q',
                 '-z', 'follow,tls,ascii,0',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('http://www.gnu.org/software/gnutls'))
 
-    def test_tls12_psk_aes256gcm(self):
+    def test_tls12_psk_aes256gcm(self, cmd_tshark, capture_file):
         '''TLS 1.2 with PSK, AES-256-GCM'''
-        capture_file = os.path.join(config.capture_dir, 'tls12-aes256gcm.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('tls12-aes256gcm.pcap'),
                 '-o', 'tls.psk:ca19e028a8a372ad2d325f950fcaceed',
                 '-q',
                 '-z', 'follow,tls,ascii,0',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('http://www.gnu.org/software/gnutls'))
 
-    def test_tls12_chacha20poly1305(self):
+    def test_tls12_chacha20poly1305(self, cmd_tshark, dirs, features, capture_file):
         '''TLS 1.2 with ChaCha20-Poly1305'''
-        if not config.have_libgcrypt17:
+        if not features.have_libgcrypt17:
             self.skipTest('Requires GCrypt 1.7 or later.')
-        capture_file = os.path.join(config.capture_dir, 'tls12-chacha20poly1305.pcap')
-        key_file = os.path.join(config.key_dir, 'tls12-chacha20poly1305.keys')
+        key_file = os.path.join(dirs.key_dir, 'tls12-chacha20poly1305.keys')
         ciphers=[
             'ECDHE-ECDSA-CHACHA20-POLY1305',
             'ECDHE-RSA-CHACHA20-POLY1305',
@@ -236,39 +214,35 @@ class case_decrypt_tls(subprocesstest.SubprocessTestCase):
         ]
         stream = 0
         for cipher in ciphers:
-            self.runProcess((config.cmd_tshark,
-                    '-r', capture_file,
+            self.runProcess((cmd_tshark,
+                    '-r', capture_file('tls12-chacha20poly1305.pcap'),
                     '-o', 'tls.keylog_file: {}'.format(key_file),
                     '-q',
                     '-z', 'follow,tls,ascii,{}'.format(stream),
-                ),
-                env=config.test_env)
+                ))
             stream += 1
             self.assertTrue(self.grepOutput('Cipher is {}'.format(cipher)))
 
-    def test_tls13_chacha20poly1305(self):
+    def test_tls13_chacha20poly1305(self, cmd_tshark, dirs, features, capture_file):
         '''TLS 1.3 with ChaCha20-Poly1305'''
-        if not config.have_libgcrypt17:
+        if not features.have_libgcrypt17:
             self.skipTest('Requires GCrypt 1.7 or later.')
-        capture_file = os.path.join(config.capture_dir, 'tls13-20-chacha20poly1305.pcap')
-        key_file = os.path.join(config.key_dir, 'tls13-20-chacha20poly1305.keys')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        key_file = os.path.join(dirs.key_dir, 'tls13-20-chacha20poly1305.keys')
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('tls13-20-chacha20poly1305.pcap'),
                 '-o', 'tls.keylog_file: {}'.format(key_file),
                 '-q',
                 '-z', 'follow,tls,ascii,0',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('TLS13-CHACHA20-POLY1305-SHA256'))
 
-    def test_tls13_rfc8446(self):
+    def test_tls13_rfc8446(self, cmd_tshark, dirs, features, capture_file):
         '''TLS 1.3 (normal session, then early data followed by normal data).'''
-        if not config.have_libgcrypt16:
+        if not features.have_libgcrypt16:
             self.skipTest('Requires GCrypt 1.6 or later.')
-        capture_file = os.path.join(config.capture_dir, 'tls13-rfc8446.pcap')
-        key_file = os.path.join(config.key_dir, 'tls13-rfc8446.keys')
-        proc = self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        key_file = os.path.join(dirs.key_dir, 'tls13-rfc8446.keys')
+        proc = self.runProcess((cmd_tshark,
+                '-r', capture_file('tls13-rfc8446.pcap'),
                 '-otls.keylog_file:{}'.format(key_file),
                 '-Y', 'http',
                 '-Tfields',
@@ -276,8 +250,7 @@ class case_decrypt_tls(subprocesstest.SubprocessTestCase):
                 '-e', 'http.request.uri',
                 '-e', 'http.file_data',
                 '-E', 'separator=|',
-            ),
-            env=config.test_env)
+            ))
         self.assertEqual([
             r'5|/first|',
             r'6||Request for /first, version TLSv1.3, Early data: no\n',
@@ -287,14 +260,13 @@ class case_decrypt_tls(subprocesstest.SubprocessTestCase):
             r'13||Request for /second, version TLSv1.3, Early data: yes\n',
         ], proc.stdout_str.splitlines())
 
-    def test_tls13_rfc8446_noearly(self):
+    def test_tls13_rfc8446_noearly(self, cmd_tshark, dirs, features, capture_file):
         '''TLS 1.3 (with undecryptable early data).'''
-        if not config.have_libgcrypt16:
+        if not features.have_libgcrypt16:
             self.skipTest('Requires GCrypt 1.6 or later.')
-        capture_file = os.path.join(config.capture_dir, 'tls13-rfc8446.pcap')
-        key_file = os.path.join(config.key_dir, 'tls13-rfc8446-noearly.keys')
-        proc = self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        key_file = os.path.join(dirs.key_dir, 'tls13-rfc8446-noearly.keys')
+        proc = self.runProcess((cmd_tshark,
+                '-r', capture_file('tls13-rfc8446.pcap'),
                 '-otls.keylog_file:{}'.format(key_file),
                 '-Y', 'http',
                 '-Tfields',
@@ -302,8 +274,7 @@ class case_decrypt_tls(subprocesstest.SubprocessTestCase):
                 '-e', 'http.request.uri',
                 '-e', 'http.file_data',
                 '-E', 'separator=|',
-            ),
-            env=config.test_env)
+            ))
         self.assertEqual([
             r'5|/first|',
             r'6||Request for /first, version TLSv1.3, Early data: no\n',
@@ -313,233 +284,238 @@ class case_decrypt_tls(subprocesstest.SubprocessTestCase):
         ], proc.stdout_str.splitlines())
 
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_zigbee(subprocesstest.SubprocessTestCase):
-    def test_zigbee(self):
+    def test_zigbee(self, cmd_tshark, capture_file):
         '''ZigBee'''
         # https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7022
-        capture_file = os.path.join(config.capture_dir, 'sample_control4_2012-03-24.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('sample_control4_2012-03-24.pcap'),
                 '-Tfields',
                 '-e', 'data.data',
                 '-Y', 'zbee_aps',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('3067636338652063342e646d2e747620'))
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_ansi_c1222(subprocesstest.SubprocessTestCase):
-    def test_ansi_c1222(self):
+    def test_ansi_c1222(self, cmd_tshark, capture_file):
         '''ANSI C12.22'''
         # https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9196
-        capture_file = os.path.join(config.capture_dir, 'c1222_std_example8.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('c1222_std_example8.pcap'),
                 '-o', 'c1222.decrypt: TRUE',
                 '-o', 'c1222.baseoid: 2.16.124.113620.1.22.0',
                 '-Tfields',
                 '-e', 'c1222.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('00104d414e55464143545552455220534e2092'))
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_dvb_ci(subprocesstest.SubprocessTestCase):
-    def test_dvb_ci(self):
+    def test_dvb_ci(self, cmd_tshark, capture_file):
         '''DVB-CI'''
         # simplified version of the sample capture in
         # https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6700
-        capture_file = os.path.join(config.capture_dir, 'dvb-ci_UV1_0000.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('dvb-ci_UV1_0000.pcap'),
                 '-o', 'dvb-ci.sek: 00000000000000000000000000000000',
                 '-o', 'dvb-ci.siv: 00000000000000000000000000000000',
                 '-Tfields',
                 '-e', 'dvb-ci.cc.sac.padding',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('800000000000000000000000'))
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_ipsec(subprocesstest.SubprocessTestCase):
-    def test_ipsec_esp(self):
+    def test_ipsec_esp(self, cmd_tshark, capture_file):
         '''IPsec ESP'''
         # https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=12671
-        capture_file = os.path.join(config.capture_dir, 'esp-bug-12671.pcapng.gz')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('esp-bug-12671.pcapng.gz'),
                 '-o', 'esp.enable_encryption_decode: TRUE',
                 '-Tfields',
                 '-e', 'data.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('08090a0b0c0d0e0f1011121314151617'))
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_ike_isakmp(subprocesstest.SubprocessTestCase):
-    def test_ikev1_certs(self):
+    def test_ikev1_certs(self, cmd_tshark, capture_file):
         '''IKEv1 (ISAKMP) with certificates'''
         # https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7951
-        capture_file = os.path.join(config.capture_dir, 'ikev1-certs.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev1-certs.pcap'),
                 '-Tfields',
                 '-e', 'x509sat.printableString',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('OpenSwan'))
 
-    def test_ikev1_simultaneous(self):
+    def test_ikev1_simultaneous(self, cmd_tshark, capture_file):
         '''IKEv1 (ISAKMP) simultaneous exchanges'''
         # https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=12610
-        capture_file = os.path.join(config.capture_dir, 'ikev1-bug-12610.pcapng.gz')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev1-bug-12610.pcapng.gz'),
                 '-Tfields',
                 '-e', 'isakmp.hash',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('b52521f774967402c9f6cee95fd17e5b'))
 
-    def test_ikev1_unencrypted(self):
+    def test_ikev1_unencrypted(self, cmd_tshark, capture_file):
         '''IKEv1 (ISAKMP) unencrypted phase 1'''
         # https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=12620
-        capture_file = os.path.join(config.capture_dir, 'ikev1-bug-12620.pcapng.gz')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev1-bug-12620.pcapng.gz'),
                 '-Tfields',
                 '-e', 'isakmp.hash',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('40043b640f4373250d5ac3a1fb63153c'))
 
-    def test_ikev2_3des_sha160(self):
+    def test_ikev2_3des_sha160(self, cmd_tshark, capture_file):
         '''IKEv2 decryption test (3DES-CBC/SHA1_160)'''
-        capture_file = os.path.join(config.capture_dir, 'ikev2-decrypt-3des-sha1_160.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev2-decrypt-3des-sha1_160.pcap'),
                 '-Tfields',
                 '-e', 'isakmp.auth.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('02f7a0d5f1fdc8ea81039818c65bb9bd09af9b8917319b887ff9ba3046c344c7'))
 
-    def test_ikev2_aes128_ccm12(self):
+    def test_ikev2_aes128_ccm12(self, cmd_tshark, capture_file):
         '''IKEv2 decryption test (AES-128-CCM-12) - with CBC-MAC verification'''
-        capture_file = os.path.join(config.capture_dir, 'ikev2-decrypt-aes128ccm12.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev2-decrypt-aes128ccm12.pcap'),
                 '-Tfields',
                 '-e', 'isakmp.auth.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('c2104394299e1ffe7908ea720ad5d13717a0d454e4fa0a2128ea689411f479c4'))
 
-    def test_ikev2_aes128_ccm12_2(self):
+    def test_ikev2_aes128_ccm12_2(self, cmd_tshark, capture_file):
         '''IKEv2 decryption test (AES-128-CCM-12 using CTR mode, without checksum)'''
-        capture_file = os.path.join(config.capture_dir, 'ikev2-decrypt-aes128ccm12-2.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev2-decrypt-aes128ccm12-2.pcap'),
                 '-Tfields',
                 '-e', 'isakmp.auth.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('aaa281c87b4a19046c57271d557488ca413b57228cb951f5fa9640992a0285b9'))
 
-    def test_ikev2_aes192ctr_sha512(self):
+    def test_ikev2_aes192ctr_sha512(self, cmd_tshark, capture_file):
         '''IKEv2 decryption test (AES-192-CTR/SHA2-512)'''
-        capture_file = os.path.join(config.capture_dir, 'ikev2-decrypt-aes192ctr.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev2-decrypt-aes192ctr.pcap'),
                 '-Tfields',
                 '-e', 'isakmp.auth.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('3ec23dcf9348485638407c754547aeb3085290082c49f583fdbae59263a20b4a'))
 
-    def test_ikev2_aes256cbc_sha256(self):
+    def test_ikev2_aes256cbc_sha256(self, cmd_tshark, capture_file):
         '''IKEv2 decryption test (AES-256-CBC/SHA2-256)'''
-        capture_file = os.path.join(config.capture_dir, 'ikev2-decrypt-aes256cbc.pcapng')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev2-decrypt-aes256cbc.pcapng'),
                 '-Tfields',
                 '-e', 'isakmp.auth.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('e1a8d550064201a7ec024a85758d0673c61c5c510ac13bcd225d6327f50da3d3'))
 
-    def test_ikev2_aes256ccm16(self):
+    def test_ikev2_aes256ccm16(self, cmd_tshark, capture_file):
         '''IKEv2 decryption test (AES-256-CCM-16)'''
-        capture_file = os.path.join(config.capture_dir, 'ikev2-decrypt-aes256ccm16.pcapng')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev2-decrypt-aes256ccm16.pcapng'),
                 '-Tfields',
                 '-e', 'isakmp.auth.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('fa2e74bdc01e30fb0b3ddc9723c9449095969da51f69e560209d2c2b7940210a'))
 
-    def test_ikev2_aes256gcm16(self):
+    def test_ikev2_aes256gcm16(self, cmd_tshark, capture_file):
         '''IKEv2 decryption test (AES-256-GCM-16)'''
-        capture_file = os.path.join(config.capture_dir, 'ikev2-decrypt-aes256gcm16.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev2-decrypt-aes256gcm16.pcap'),
                 '-Tfields',
                 '-e', 'isakmp.auth.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('9ab71f14ab553cad873a1aa70b99df155dee77cdcf3694b3b7527acbb9712ded'))
 
-    def test_ikev2_aes256gcm8(self):
+    def test_ikev2_aes256gcm8(self, cmd_tshark, capture_file):
         '''IKEv2 decryption test (AES-256-GCM-8)'''
-        capture_file = os.path.join(config.capture_dir, 'ikev2-decrypt-aes256gcm8.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('ikev2-decrypt-aes256gcm8.pcap'),
                 '-Tfields',
                 '-e', 'isakmp.auth.data',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput('4a66d822d0afbc22ad9a92a2cf4287c920ad8ac3b069a4a7e75fe0a5d499f914'))
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_http2(subprocesstest.SubprocessTestCase):
-    def test_http2(self):
+    def test_http2(self, cmd_tshark, capture_file, features):
         '''HTTP2 (HPACK)'''
-        if not config.have_nghttp2:
+        if not features.have_nghttp2:
             self.skipTest('Requires nghttp2.')
-        capture_file = os.path.join(config.capture_dir, 'packet-h2-14_headers.pcapng')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('packet-h2-14_headers.pcapng'),
                 '-Tfields',
                 '-e', 'http2.header.value',
                 '-d', 'tcp.port==3000,http2',
-            ),
-            env=config.test_env)
+            ))
         test_passed = self.grepOutput('nghttp2')
         if not test_passed:
             self.log_fd.write('\n\n-- Verbose output --\n\n')
-            self.runProcess((config.cmd_tshark,
-                    '-r', capture_file,
+            self.runProcess((cmd_tshark,
+                    '-r', capture_file('packet-h2-14_headers.pcapng'),
                     '-V',
                     '-d', 'tcp.port==3000,http2',
-                ),
-                env=config.test_env)
+                ))
         self.assertTrue(test_passed)
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_kerberos(subprocesstest.SubprocessTestCase):
-    def test_kerberos(self):
+    def test_kerberos(self, cmd_tshark, dirs, features, capture_file):
         '''Kerberos'''
         # Files are from krb-816.zip on the SampleCaptures page.
-        if not config.have_kerberos:
+        if not features.have_kerberos:
             self.skipTest('Requires kerberos.')
-        capture_file = os.path.join(config.capture_dir, 'krb-816.pcap.gz')
-        keytab_file = os.path.join(config.key_dir, 'krb-816.keytab')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        keytab_file = os.path.join(dirs.key_dir, 'krb-816.keytab')
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('krb-816.pcap.gz'),
                 '-o', 'kerberos.decrypt: TRUE',
                 '-o', 'kerberos.file: {}'.format(keytab_file),
                 '-Tfields',
                 '-e', 'kerberos.keyvalue',
-            ),
-            env=config.test_env)
+            ))
         # keyvalue: ccda7d48219f73c3b28311c4ba7242b3
         self.assertTrue(self.grepOutput('ccda7d48219f73c3b28311c4ba7242b3'))
 
+
+@fixtures.fixture(scope='session')
+def run_wireguard_test(cmd_tshark, capture_file, features):
+    if not features.have_libgcrypt17:
+        fixtures.skip('Requires Gcrypt 1.7 or later')
+    def runOne(self, args, keylog=None, pcap_file='wireguard-ping-tcp.pcap'):
+        if keylog:
+            keylog_file = self.filename_from_id('wireguard.keys')
+            args += ['-owg.keylog_file:%s' % keylog_file]
+            with open(keylog_file, 'w') as f:
+                f.write("\n".join(keylog))
+        proc = self.runProcess([cmd_tshark, '-r', capture_file(pcap_file)] + args)
+        lines = proc.stdout_str.splitlines()
+        return lines
+    return runOne
+
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
     # The "foo_alt" keys are similar as "foo" except that some bits are changed.
     # The crypto library should be able to handle this and internally the
@@ -564,23 +540,9 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
     # dummy key that should not work with anything.
     key_dummy = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx='
 
-    def runOne(self, args, keylog=None, pcap_file='wireguard-ping-tcp.pcap'):
-        if not config.have_libgcrypt17:
-            self.skipTest('Requires Gcrypt 1.7 or later')
-        capture_file = os.path.join(config.capture_dir, pcap_file)
-        if keylog:
-            keylog_file = self.filename_from_id('wireguard.keys')
-            args += ['-owg.keylog_file:%s' % keylog_file]
-            with open(keylog_file, 'w') as f:
-                f.write("\n".join(keylog))
-        proc = self.runProcess([config.cmd_tshark, '-r', capture_file] + args,
-                               env=config.test_env)
-        lines = proc.stdout_str.splitlines()
-        return lines
-
-    def test_mac1_public(self):
+    def test_mac1_public(self, run_wireguard_test):
         """Check that MAC1 identification using public keys work."""
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-ouat:wg_keys:"Public","%s"' % self.key_Spub_i,
             '-ouat:wg_keys:"Public","%s"' % self.key_Spub_r,
             '-Y', 'wg.receiver_pubkey',
@@ -595,9 +557,9 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('13\t%s\t0' % self.key_Spub_r, lines)
         self.assertIn('14\t%s\t0' % self.key_Spub_i, lines)
 
-    def test_mac1_private(self):
+    def test_mac1_private(self, run_wireguard_test):
         """Check that MAC1 identification using private keys work."""
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-ouat:wg_keys:"Private","%s"' % self.key_Spriv_i,
             '-ouat:wg_keys:"Private","%s"' % self.key_Spriv_r,
             '-Y', 'wg.receiver_pubkey',
@@ -612,9 +574,9 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('13\t%s\t1' % self.key_Spub_r, lines)
         self.assertIn('14\t%s\t1' % self.key_Spub_i, lines)
 
-    def test_decrypt_initiation_sprivr(self):
+    def test_decrypt_initiation_sprivr(self, run_wireguard_test):
         """Check for partial decryption using Spriv_r."""
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-ouat:wg_keys:"Private","%s"' % self.key_Spriv_r,
             '-Y', 'wg.type==1',
             '-Tfields',
@@ -628,9 +590,9 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('1\t%s\t0\t0\t%s' % (self.key_Spub_i, '356537872'), lines)
         self.assertIn('13\t%s\t0\t0\t%s' % (self.key_Spub_i, '490514356'), lines)
 
-    def test_decrypt_initiation_ephemeral_only(self):
+    def test_decrypt_initiation_ephemeral_only(self, run_wireguard_test):
         """Check for partial decryption using Epriv_i."""
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-ouat:wg_keys:"Public","%s"' % self.key_Spub_r,
             '-Y', 'wg.type==1',
             '-Tfields',
@@ -647,12 +609,12 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('1\t1\t%s\t%s' % (self.key_Spub_i, ''), lines)
         self.assertIn('13\t1\t%s\t%s' % (self.key_Spub_i, ''), lines)
 
-    def test_decrypt_full_initiator(self):
+    def test_decrypt_full_initiator(self, run_wireguard_test):
         """
         Check for full handshake decryption using Spriv_r + Epriv_i.
         The public key Spub_r is provided via the key log as well.
         """
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-Tfields',
             '-e', 'frame.number',
             '-e', 'wg.ephemeral.known_privkey',
@@ -676,9 +638,9 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('17\t\t\t\t\t\t443', lines)
         self.assertIn('18\t\t\t\t\t\t49472', lines)
 
-    def test_decrypt_full_responder(self):
+    def test_decrypt_full_responder(self, run_wireguard_test):
         """Check for full handshake decryption using responder secrets."""
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-Tfields',
             '-e', 'frame.number',
             '-e', 'wg.ephemeral.known_privkey',
@@ -702,9 +664,9 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('17\t\t\t\t\t\t443', lines)
         self.assertIn('18\t\t\t\t\t\t49472', lines)
 
-    def test_decrypt_psk_initiator(self):
+    def test_decrypt_psk_initiator(self, run_wireguard_test):
         """Check whether PSKs enable decryption for initiation keys."""
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-Tfields',
             '-e', 'frame.number',
             '-e', 'wg.handshake_ok',
@@ -719,9 +681,9 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('2\t1', lines)
         self.assertIn('4\t1', lines)
 
-    def test_decrypt_psk_responder(self):
+    def test_decrypt_psk_responder(self, run_wireguard_test):
         """Check whether PSKs enable decryption for responder keys."""
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-Tfields',
             '-e', 'frame.number',
             '-e', 'wg.handshake_ok',
@@ -744,9 +706,9 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('2\t1', lines)
         self.assertIn('4\t1', lines)
 
-    def test_decrypt_psk_wrong_orderl(self):
+    def test_decrypt_psk_wrong_orderl(self, run_wireguard_test):
         """Check that the wrong order of lines indeed fail decryption."""
-        lines = self.runOne([
+        lines = run_wireguard_test(self, [
             '-Tfields',
             '-e', 'frame.number',
             '-e', 'wg.handshake_ok',
@@ -761,96 +723,85 @@ class case_decrypt_wireguard(subprocesstest.SubprocessTestCase):
         self.assertIn('2\t0', lines)
         self.assertIn('4\t0', lines)
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_decrypt_knxip(subprocesstest.SubprocessTestCase):
     # Capture files for these tests contain single telegrams.
     # For realistic (live captured) KNX/IP telegram sequences, see:
     # https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=14825
 
-    def test_knxip_data_security_decryption_ok(self):
+    def test_knxip_data_security_decryption_ok(self, cmd_tshark, capture_file):
         '''KNX/IP: Data Security decryption OK'''
-        # capture_file contains KNX/IP ConfigReq DataSec PropExtValueWriteCon telegram
-        capture_file = os.path.join(config.capture_dir, 'knxip_DataSec.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        # capture_file('knxip_DataSec.pcap') contains KNX/IP ConfigReq DataSec PropExtValueWriteCon telegram
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('knxip_DataSec.pcap'),
                 '-o', 'kip.key_1:00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput(' DataSec '))
         self.assertTrue(self.grepOutput(' PropExtValueWriteCon '))
 
-    def test_knxip_data_security_decryption_fails(self):
+    def test_knxip_data_security_decryption_fails(self, cmd_tshark, capture_file):
         '''KNX/IP: Data Security decryption fails'''
-        # capture_file contains KNX/IP ConfigReq DataSec PropExtValueWriteCon telegram
-        capture_file = os.path.join(config.capture_dir, 'knxip_DataSec.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        # capture_file('knxip_DataSec.pcap') contains KNX/IP ConfigReq DataSec PropExtValueWriteCon telegram
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('knxip_DataSec.pcap'),
                 '-o', 'kip.key_1:""', # "" is really necessary, otherwise test fails
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput(' DataSec '))
         self.assertFalse(self.grepOutput(' PropExtValueWriteCon '))
 
-    def test_knxip_secure_wrapper_decryption_ok(self):
+    def test_knxip_secure_wrapper_decryption_ok(self, cmd_tshark, capture_file):
         '''KNX/IP: SecureWrapper decryption OK'''
-        # capture_file contains KNX/IP SecureWrapper RoutingInd telegram
-        capture_file = os.path.join(config.capture_dir, 'knxip_SecureWrapper.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        # capture_file('knxip_SecureWrapper.pcap') contains KNX/IP SecureWrapper RoutingInd telegram
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('knxip_SecureWrapper.pcap'),
                 '-o', 'kip.key_1:00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput(' SecureWrapper '))
         self.assertTrue(self.grepOutput(' RoutingInd '))
 
-    def test_knxip_secure_wrapper_decryption_fails(self):
+    def test_knxip_secure_wrapper_decryption_fails(self, cmd_tshark, capture_file):
         '''KNX/IP: SecureWrapper decryption fails'''
-        # capture_file contains KNX/IP SecureWrapper RoutingInd telegram
-        capture_file = os.path.join(config.capture_dir, 'knxip_SecureWrapper.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        # capture_file('knxip_SecureWrapper.pcap') contains KNX/IP SecureWrapper RoutingInd telegram
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('knxip_SecureWrapper.pcap'),
                 '-o', 'kip.key_1:""', # "" is really necessary, otherwise test fails
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput(' SecureWrapper '))
         self.assertFalse(self.grepOutput(' RoutingInd '))
 
-    def test_knxip_timer_notify_authentication_ok(self):
+    def test_knxip_timer_notify_authentication_ok(self, cmd_tshark, capture_file):
         '''KNX/IP: TimerNotify authentication OK'''
-        # capture_file contains KNX/IP TimerNotify telegram
-        capture_file = os.path.join(config.capture_dir, 'knxip_TimerNotify.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        # capture_file('knxip_TimerNotify.pcap') contains KNX/IP TimerNotify telegram
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('knxip_TimerNotify.pcap'),
                 '-o', 'kip.key_1:00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F',
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput(' TimerNotify '))
         self.assertTrue(self.grepOutput(' OK$'))
 
-    def test_knxip_timer_notify_authentication_fails(self):
+    def test_knxip_timer_notify_authentication_fails(self, cmd_tshark, capture_file):
         '''KNX/IP: TimerNotify authentication fails'''
-        # capture_file contains KNX/IP TimerNotify telegram
-        capture_file = os.path.join(config.capture_dir, 'knxip_TimerNotify.pcap')
-        self.runProcess((config.cmd_tshark,
-                '-r', capture_file,
+        # capture_file('knxip_TimerNotify.pcap') contains KNX/IP TimerNotify telegram
+        self.runProcess((cmd_tshark,
+                '-r', capture_file('knxip_TimerNotify.pcap'),
                 '-o', 'kip.key_1:""', # "" is really necessary, otherwise test fails
-            ),
-            env=config.test_env)
+            ))
         self.assertTrue(self.grepOutput(' TimerNotify '))
         self.assertFalse(self.grepOutput(' OK$'))
 
-    def test_knxip_keyring_xml_import(self):
+    def test_knxip_keyring_xml_import(self, cmd_tshark, dirs, capture_file):
         '''KNX/IP: keyring.xml import'''
         # key_file "keyring.xml" contains KNX decryption keys
-        key_file = os.path.join(config.key_dir, 'knx_keyring.xml')
-        # capture_file is empty
-        capture_file = os.path.join(config.capture_dir, 'empty.pcap')
+        key_file = os.path.join(dirs.key_dir, 'knx_keyring.xml')
+        # capture_file('empty.pcap') is empty
         # Write extracted key info to stdout
-        self.runProcess((config.cmd_tshark,
+        self.runProcess((cmd_tshark,
                 '-o', 'kip.key_file:' + key_file,
                 '-o', 'kip.key_info_file:-',
-                '-r', capture_file,
-            ),
-            env=config.test_env)
+                '-r', capture_file('empty.pcap'),
+            ))
         self.assertTrue(self.grepOutput('^MCA 224[.]0[.]23[.]12 key A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF$'))
         self.assertTrue(self.grepOutput('^GA 1/7/131 sender 1[.]1[.]1$'))
         self.assertTrue(self.grepOutput('^GA 1/7/131 sender 1[.]1[.]3$'))
index 2dedd4d3fa6f4e897aa68e5a021fcc2b293e23b6..dc258a0efd9d26e2b99d39623c10dc40db8055a1 100644 (file)
@@ -17,14 +17,13 @@ import fixtures
 @fixtures.mark_usefixtures('test_env')
 @fixtures.uses_fixtures
 class case_dissect_http2(subprocesstest.SubprocessTestCase):
-    def test_http2_data_reassembly(self, cmd_tshark, features, dirs):
+    def test_http2_data_reassembly(self, cmd_tshark, features, dirs, capture_file):
         '''HTTP2 data reassembly'''
         if not features.have_nghttp2:
             self.skipTest('Requires nghttp2.')
-        capture_file = os.path.join(dirs.capture_dir, 'http2-data-reassembly.pcap')
         key_file = os.path.join(dirs.key_dir, 'http2-data-reassembly.keys')
         self.runProcess((cmd_tshark,
-                '-r', capture_file,
+                '-r', capture_file('http2-data-reassembly.pcap'),
                 '-o', 'tls.keylog_file: {}'.format(key_file),
                 '-d', 'tcp.port==8443,tls',
                 '-Y', 'http2.data.data matches "PNG" && http2.data.data matches "END"',
@@ -59,12 +58,11 @@ class case_dissect_tcp(subprocesstest.SubprocessTestCase):
     def test_tcp_out_of_order_twopass(self, cmd_tshark, dirs):
         self.check_tcp_out_of_order(cmd_tshark, dirs, extraArgs=['-2'])
 
-    def test_tcp_out_of_order_twopass_with_bug(self, cmd_tshark, dirs):
+    def test_tcp_out_of_order_twopass_with_bug(self, cmd_tshark, capture_file):
         # TODO fix the issue below, remove this and enable
         # "test_tcp_out_of_order_twopass"
-        capture_file = os.path.join(dirs.capture_dir, 'http-ooo.pcap')
         self.runProcess((cmd_tshark,
-                '-r', capture_file,
+                '-r', capture_file('http-ooo.pcap'),
                 '-otcp.reassemble_out_of_order:TRUE',
                 '-Y', 'http',
                 '-2',
@@ -81,11 +79,10 @@ class case_dissect_tcp(subprocesstest.SubprocessTestCase):
         self.assertTrue(self.grepOutput(r'^\s*11\s.*PUT /4 HTTP/1.1'))
         self.assertTrue(self.grepOutput(r'^\s*15\s.*PUT /5 HTTP/1.1'))
 
-    def test_tcp_out_of_order_data_after_syn(self, cmd_tshark, dirs):
+    def test_tcp_out_of_order_data_after_syn(self, cmd_tshark, capture_file):
         '''Test when the first non-empty segment is OoO.'''
-        capture_file = os.path.join(dirs.capture_dir, 'dns-ooo.pcap')
         proc = self.runProcess((cmd_tshark,
-                '-r', capture_file,
+                '-r', capture_file('dns-ooo.pcap'),
                 '-otcp.reassemble_out_of_order:TRUE',
                 '-Y', 'dns', '-Tfields', '-edns.qry.name',
             ))
index 3c3f55136b06b4e4f414d74631e22a6c68182348..86be14d378ac3d718e9a0f58531bdbb308770749 100644 (file)
@@ -9,11 +9,8 @@
 #
 '''File format conversion tests'''
 
-import config
-import io
 import os.path
 import subprocesstest
-import sys
 import unittest
 import fixtures
 
@@ -24,102 +21,103 @@ time_output_args = ('-Tfields', '-e', 'frame.number', '-e', 'frame.time_epoch',
 # tshark -Tfields -e frame.number -e frame.time_epoch -e frame.time_delta \
 #   -r captures/dhcp.pcap > baseline/ff-ts-usec-pcap-direct.txt
 baseline_file = 'ff-ts-usec-pcap-direct.txt'
-baseline_fd = io.open(os.path.join(config.baseline_dir, baseline_file), 'r', encoding='UTF-8', errors='replace')
-baseline_str = baseline_fd.read()
-baseline_fd.close()
 
+
+@fixtures.fixture(scope='session')
+def fileformats_baseline_str(dirs):
+    with open(os.path.join(dirs.baseline_dir, baseline_file), 'r') as f:
+        return f.read()
+
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_fileformat_pcap(subprocesstest.SubprocessTestCase):
-    def test_pcap_usec_stdin(self):
+    def test_pcap_usec_stdin(self, cmd_tshark, capture_file, fileformats_baseline_str):
         '''Microsecond pcap direct vs microsecond pcap stdin'''
-        capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
-        capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
+        capture_proc = self.runProcess(subprocesstest.capture_command(cmd_tshark,
                 '-r', '-',
                 '-Tfields',
                 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
-                '<', capture_file
+                '<', capture_file('dhcp.pcap')
                 , shell=True),
             shell=True)
-        self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
+        self.assertTrue(self.diffOutput(capture_proc.stdout_str, fileformats_baseline_str, 'tshark', baseline_file))
 
-    def test_pcap_nsec_stdin(self):
+    def test_pcap_nsec_stdin(self, cmd_tshark, capture_file, fileformats_baseline_str):
         '''Microsecond pcap direct vs nanosecond pcap stdin'''
-        capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcap')
-        capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
+        capture_proc = self.runProcess(subprocesstest.capture_command(cmd_tshark,
                 '-r', '-',
                 '-Tfields',
                 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
-                '<', capture_file
+                '<', capture_file('dhcp-nanosecond.pcap')
                 , shell=True),
             shell=True)
-        self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
+        self.assertTrue(self.diffOutput(capture_proc.stdout_str, fileformats_baseline_str, 'tshark', baseline_file))
 
-    def test_pcap_nsec_direct(self):
+    def test_pcap_nsec_direct(self, cmd_tshark, capture_file, fileformats_baseline_str):
         '''Microsecond pcap direct vs nanosecond pcap direct'''
-        capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcap')
-        capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
-                '-r', capture_file,
+        capture_proc = self.runProcess(subprocesstest.capture_command(cmd_tshark,
+                '-r', capture_file('dhcp-nanosecond.pcap'),
                 '-Tfields',
                 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
                 ),
             )
-        self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
+        self.assertTrue(self.diffOutput(capture_proc.stdout_str, fileformats_baseline_str, 'tshark', baseline_file))
+
 
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_fileformat_pcapng(subprocesstest.SubprocessTestCase):
-    def test_pcapng_usec_stdin(self):
+    def test_pcapng_usec_stdin(self, cmd_tshark, capture_file, fileformats_baseline_str):
         '''Microsecond pcap direct vs microsecond pcapng stdin'''
-        capture_file = os.path.join(config.capture_dir, 'dhcp.pcapng')
-        capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
+        capture_proc = self.runProcess(subprocesstest.capture_command(cmd_tshark,
                 '-r', '-',
                 '-Tfields',
                 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta'
-                '<', capture_file
+                '<', capture_file('dhcp.pcapng')
                 , shell=True),
             shell=True)
-        self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
+        self.assertTrue(self.diffOutput(capture_proc.stdout_str, fileformats_baseline_str, 'tshark', baseline_file))
 
-    def test_pcapng_usec_direct(self):
+    def test_pcapng_usec_direct(self, cmd_tshark, capture_file, fileformats_baseline_str):
         '''Microsecond pcap direct vs microsecond pcapng direct'''
-        capture_file = os.path.join(config.capture_dir, 'dhcp.pcapng')
-        capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
-                '-r', capture_file,
+        capture_proc = self.runProcess(subprocesstest.capture_command(cmd_tshark,
+                '-r', capture_file('dhcp.pcapng'),
                 '-Tfields',
                 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
                 ),
             )
-        self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
+        self.assertTrue(self.diffOutput(capture_proc.stdout_str, fileformats_baseline_str, 'tshark', baseline_file))
 
-    def test_pcapng_nsec_stdin(self):
+    def test_pcapng_nsec_stdin(self, cmd_tshark, capture_file, fileformats_baseline_str):
         '''Microsecond pcap direct vs nanosecond pcapng stdin'''
-        capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcapng')
-        capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
+        capture_proc = self.runProcess(subprocesstest.capture_command(cmd_tshark,
                 '-r', '-',
                 '-Tfields',
                 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta'
-                '<', capture_file
+                '<', capture_file('dhcp-nanosecond.pcapng')
                 , shell=True),
             shell=True)
-        self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
+        self.assertTrue(self.diffOutput(capture_proc.stdout_str, fileformats_baseline_str, 'tshark', baseline_file))
 
-    def test_pcapng_nsec_direct(self):
+    def test_pcapng_nsec_direct(self, cmd_tshark, capture_file, fileformats_baseline_str):
         '''Microsecond pcap direct vs nanosecond pcapng direct'''
-        capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcapng')
-        capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
-                '-r', capture_file,
+        capture_proc = self.runProcess(subprocesstest.capture_command(cmd_tshark,
+                '-r', capture_file('dhcp-nanosecond.pcapng'),
                 '-Tfields',
                 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
                 ),
             )
-        self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
+        self.assertTrue(self.diffOutput(capture_proc.stdout_str, fileformats_baseline_str, 'tshark', baseline_file))
 
 
 @fixtures.mark_usefixtures('test_env')
 @fixtures.uses_fixtures
 class case_fileformat_mime(subprocesstest.SubprocessTestCase):
-    def test_mime_pcapng_gz(self, cmd_tshark, dirs):
+    def test_mime_pcapng_gz(self, cmd_tshark, capture_file):
         '''Test that the full uncompressed contents is shown.'''
-        capture_file = os.path.join(dirs.capture_dir, 'icmp.pcapng.gz')
         proc = self.runProcess((cmd_tshark,
-                '-r', capture_file,
+                '-r', capture_file('icmp.pcapng.gz'),
                 '-Xread_format:MIME Files Format',
                 '-Tfields', '-e', 'frame.len', '-e', 'pcapng.block.length',
             ))
index 4a216d3f7427a84cf1d4ec194a9671aef5b55d42..3144bce43b93a6c21b68fe0a8b0462e59e6b6795 100644 (file)
@@ -8,14 +8,14 @@
 #
 '''Follow Stream tests'''
 
-import config
-import os.path
 import subprocesstest
-import unittest
+import fixtures
 
 
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_follow_tcp(subprocesstest.SubprocessTestCase):
-    def test_follow_tcp_bad_conditions(self):
+    def test_follow_tcp_bad_conditions(self, cmd_tshark, capture_file):
         '''Checks whether Follow TCP correctly handles lots of edge cases.'''
         # Edge cases include:
         # 1. two sequential segments
@@ -27,11 +27,10 @@ class case_follow_tcp(subprocesstest.SubprocessTestCase):
         # 6. lost but acked segments
         # 7. lost 3/5 fragments, but acked
         # Not checked: lost and not acked (currently truncated, is that OK?)
-        capture_file = os.path.join(config.capture_dir, 'tcp-badsegments.pcap')
-        proc = self.runProcess([config.cmd_tshark,
-                                '-r', capture_file,
+        proc = self.runProcess((cmd_tshark,
+                                '-r', capture_file('tcp-badsegments.pcap'),
                                 '-qz', 'follow,tcp,hex,0',
-                                ], env=config.test_env)
+                                ))
 
         self.assertIn("""\
 ===================================================================
index c8591ce69cb6880f56bebbb6d80cd4a7737dd0c9..9561b6418e2a0a831319bac2da59f983d7d69490 100644 (file)
@@ -9,27 +9,28 @@
 #
 '''File I/O tests'''
 
-import config
 import io
 import os.path
 import subprocesstest
 import sys
 import unittest
+import fixtures
 
 testout_pcap = 'testout.pcap'
 baseline_file = 'io-rawshark-dhcp-pcap.txt'
-baseline_fd = io.open(os.path.join(config.baseline_dir, baseline_file), 'r', encoding='UTF-8', errors='replace')
-baseline_str = baseline_fd.read()
-baseline_fd.close()
 
-def check_io_4_packets(self, cmd=None, from_stdin=False, to_stdout=False):
+
+@fixtures.fixture(scope='session')
+def io_baseline_str(dirs):
+    with open(os.path.join(dirs.baseline_dir, baseline_file), 'r') as f:
+        return f.read()
+
+
+def check_io_4_packets(self, capture_file, cmd=None, from_stdin=False, to_stdout=False):
     # Test direct->direct, stdin->direct, and direct->stdout file I/O.
     # Similar to suite_capture.check_capture_10_packets and
     # suite_capture.check_capture_stdin.
-    if cmd == config.cmd_wireshark and not config.canDisplay():
-        self.skipTest('Test requires a display.')
     self.assertIsNotNone(cmd)
-    capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
     testout_file = self.filename_from_id(testout_pcap)
     if from_stdin and to_stdout:
         # XXX If we support this, should we bother with separate stdin->direct
@@ -42,13 +43,12 @@ def check_io_4_packets(self, cmd=None, from_stdin=False, to_stdout=False):
         io_proc = self.runProcess(stdin_cmd, shell=True)
     elif to_stdout:
         # $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w - > ./testout.pcap 2>./testout.txt
-        stdout_cmd = '"{0}" -r "{1}" -w - > "{2}"'.format(cmd, capture_file, testout_file)
+        stdout_cmd = '"{0}" -r "{1}" -w - > "{2}"'.format(cmd, capture_file('dhcp.pcap'), testout_file)
         io_proc = self.runProcess(stdout_cmd, shell=True)
     else: # direct->direct
         # $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w ./testout.pcap > ./testout.txt 2>&1
-        capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
         io_proc = self.runProcess(subprocesstest.capture_command(cmd,
-            '-r', capture_file,
+            '-r', capture_file('dhcp.pcap'),
             '-w', testout_file,
         ))
     io_returncode = io_proc.returncode
@@ -57,33 +57,37 @@ def check_io_4_packets(self, cmd=None, from_stdin=False, to_stdout=False):
     if (io_returncode == 0):
         self.checkPacketCount(4)
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_tshark_io(subprocesstest.SubprocessTestCase):
-    def test_tshark_io_stdin_direct(self):
+    def test_tshark_io_stdin_direct(self, cmd_tshark, capture_file):
         '''Read from stdin and write direct using TShark'''
-        check_io_4_packets(self, cmd=config.cmd_tshark, from_stdin=True)
+        check_io_4_packets(self, capture_file, cmd=cmd_tshark, from_stdin=True)
 
-    def test_tshark_io_direct_stdout(self):
+    def test_tshark_io_direct_stdout(self, cmd_tshark, capture_file):
         '''Read direct and write to stdout using TShark'''
-        check_io_4_packets(self, cmd=config.cmd_tshark, to_stdout=True)
+        check_io_4_packets(self, capture_file, cmd=cmd_tshark, to_stdout=True)
 
-    def test_tshark_io_direct_direct(self):
+    def test_tshark_io_direct_direct(self, cmd_tshark, capture_file):
         '''Read direct and write direct using TShark'''
-        check_io_4_packets(self, cmd=config.cmd_tshark)
+        check_io_4_packets(self, capture_file, cmd=cmd_tshark)
 
-# The Bash version didn't test Wireshark or dumpcap
 
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_rawshark_io(subprocesstest.SubprocessTestCase):
     @unittest.skipUnless(sys.byteorder == 'little', 'Requires a little endian system')
-    def test_rawshark_io_stdin(self):
+    def test_rawshark_io_stdin(self, cmd_rawshark, capture_file, io_baseline_str):
         '''Read from stdin using Rawshark'''
         # tail -c +25 "${CAPTURE_DIR}dhcp.pcap" | $RAWSHARK -dencap:1 -R "udp.port==68" -nr - > $IO_RAWSHARK_DHCP_PCAP_TESTOUT 2> /dev/null
         # diff -u --strip-trailing-cr $IO_RAWSHARK_DHCP_PCAP_BASELINE $IO_RAWSHARK_DHCP_PCAP_TESTOUT > $DIFF_OUT 2>&1
-        capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
+        capture_file = capture_file('dhcp.pcap')
         testout_file = self.filename_from_id(testout_pcap)
         raw_dhcp_cmd = subprocesstest.cat_dhcp_command('raw')
-        rawshark_cmd = '{0} | "{1}" -r - -n -dencap:1 -R "udp.port==68"'.format(raw_dhcp_cmd, config.cmd_rawshark)
+        rawshark_cmd = '{0} | "{1}" -r - -n -dencap:1 -R "udp.port==68"'.format(raw_dhcp_cmd, cmd_rawshark)
         rawshark_proc = self.runProcess(rawshark_cmd, shell=True)
         rawshark_returncode = rawshark_proc.returncode
         self.assertEqual(rawshark_returncode, 0)
         if (rawshark_returncode == 0):
-            self.assertTrue(self.diffOutput(rawshark_proc.stdout_str, baseline_str, 'rawshark', baseline_file))
+            self.assertTrue(self.diffOutput(rawshark_proc.stdout_str, io_baseline_str, 'rawshark', baseline_file))
index 96dc497ded833616b3919dd589fae6dc3f3d61ed..8e733c09761b47a7c57c0b9f76e6f36701d52358 100644 (file)
@@ -9,20 +9,10 @@
 #
 '''Mergecap tests'''
 
-import config
-import os.path
 import re
 import subprocesstest
-import unittest
-
-dhcp_pcap = os.path.join(config.capture_dir, 'dhcp.pcap')
-dhcp_pcapng = os.path.join(config.capture_dir, 'dhcp.pcapng')
-dhcp_nanosecond_pcap = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcap')
-empty_pcap = os.path.join(config.capture_dir, 'empty.pcap')
-many_interfaces_pcapng_1 = os.path.join(config.capture_dir, 'many_interfaces.pcapng.1')
-many_interfaces_pcapng_2 = os.path.join(config.capture_dir, 'many_interfaces.pcapng.2')
-many_interfaces_pcapng_3 = os.path.join(config.capture_dir, 'many_interfaces.pcapng.3')
-rsasnakeoil2_pcap = os.path.join(config.capture_dir, 'rsasnakeoil2.pcap')
+import fixtures
+
 testout_pcap = 'testout.pcap'
 testout_pcapng = 'testout.pcapng'
 
@@ -80,182 +70,188 @@ def check_mergecap(self, mergecap_proc, file_type, encapsulation, tot_packets, g
     self.assertTrue(re.search(midb_pat, capinfos_testout) is not None,
         'Failed to merge {} IDB packets'.format(idb_packets))
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_mergecap_pcap(subprocesstest.SubprocessTestCase):
-    def test_mergecap_basic_1_pcap_pcap(self):
+    def test_mergecap_basic_1_pcap_pcap(self, cmd_mergecap, capture_file):
         '''Merge a single pcap file to pcap'''
         # $MERGECAP -vF pcap -w testout.pcap "${CAPTURE_DIR}dhcp.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-F', 'pcap',
             '-w', testout_file,
-            dhcp_pcap,
+            capture_file('dhcp.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcap', 'Ethernet', 4, 1, 4)
 
-    def test_mergecap_basic_2_pcap_pcap(self):
+    def test_mergecap_basic_2_pcap_pcap(self, cmd_mergecap, capture_file):
         '''Merge two pcap files to pcap'''
         # $MERGECAP -vF pcap -w testout.pcap "${CAPTURE_DIR}dhcp.pcap" "${CAPTURE_DIR}dhcp.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-F', 'pcap',
             '-w', testout_file,
-            dhcp_pcap, dhcp_pcap,
+            capture_file('dhcp.pcap'), capture_file('dhcp.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcap', 'Ethernet', 8, 1, 8)
 
-    def test_mergecap_basic_3_empty_pcap_pcap(self):
+    def test_mergecap_basic_3_empty_pcap_pcap(self, cmd_mergecap, capture_file):
         '''Merge three pcap files to pcap, two empty'''
         # $MERGECAP -vF pcap -w testout.pcap "${CAPTURE_DIR}empty.pcap" "${CAPTURE_DIR}dhcp.pcap" "${CAPTURE_DIR}empty.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-F', 'pcap',
             '-w', testout_file,
-            empty_pcap, dhcp_pcap, empty_pcap,
+            capture_file('empty.pcap'), capture_file('dhcp.pcap'), capture_file('empty.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcap', 'Ethernet', 4, 1, 4)
 
-    def test_mergecap_basic_2_nano_pcap_pcap(self):
+    def test_mergecap_basic_2_nano_pcap_pcap(self, cmd_mergecap, capture_file):
         '''Merge two pcap files to pcap, one with nanosecond timestamps'''
         # $MERGECAP -vF pcap -w testout.pcap "${CAPTURE_DIR}dhcp-nanosecond.pcap" "${CAPTURE_DIR}rsasnakeoil2.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcap)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-F', 'pcap',
             '-w', testout_file,
-            dhcp_nanosecond_pcap, rsasnakeoil2_pcap,
+            capture_file('dhcp-nanosecond.pcap'), capture_file('rsasnakeoil2.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcap', 'Ethernet', 62, 1, 62)
 
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_mergecap_pcapng(subprocesstest.SubprocessTestCase):
-    def test_mergecap_basic_1_pcap_pcapng(self):
+    def test_mergecap_basic_1_pcap_pcapng(self, cmd_mergecap, capture_file):
         '''Merge a single pcap file to pcapng'''
         # $MERGECAP -v -w testout.pcap "${CAPTURE_DIR}dhcp.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-w', testout_file,
-            dhcp_pcap,
+            capture_file('dhcp.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Ethernet', 4, 1, 4)
 
-    def test_mergecap_basic_2_pcap_pcapng(self):
+    def test_mergecap_basic_2_pcap_pcapng(self, cmd_mergecap, capture_file):
         '''Merge two pcap files to pcapng'''
         # $MERGECAP -v -w testout.pcap "${CAPTURE_DIR}dhcp.pcap" "${CAPTURE_DIR}dhcp.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-w', testout_file,
-            dhcp_pcap, dhcp_pcap,
+            capture_file('dhcp.pcap'), capture_file('dhcp.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Ethernet', 8, 1, 8)
 
-    def test_mergecap_basic_2_pcap_none_pcapng(self):
+    def test_mergecap_basic_2_pcap_none_pcapng(self, cmd_mergecap, capture_file):
         '''Merge two pcap files to pcapng, "none" merge mode'''
         # $MERGECAP -vI 'none' -w testout.pcap "${CAPTURE_DIR}dhcp.pcap" "${CAPTURE_DIR}dhcp.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-I', 'none',
             '-w', testout_file,
-            dhcp_pcap, dhcp_pcap,
+            capture_file('dhcp.pcap'), capture_file('dhcp.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Ethernet', 8, 2, 4)
 
-    def test_mergecap_basic_2_pcap_all_pcapng(self):
+    def test_mergecap_basic_2_pcap_all_pcapng(self, cmd_mergecap, capture_file):
         '''Merge two pcap files to pcapng, "all" merge mode'''
         # $MERGECAP -vI 'all' -w testout.pcap "${CAPTURE_DIR}dhcp.pcap" "${CAPTURE_DIR}dhcp.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-I', 'all',
             '-w', testout_file,
-            dhcp_pcap, dhcp_pcap,
+            capture_file('dhcp.pcap'), capture_file('dhcp.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Ethernet', 8, 1, 8)
 
-    def test_mergecap_basic_2_pcap_any_pcapng(self):
+    def test_mergecap_basic_2_pcap_any_pcapng(self, cmd_mergecap, capture_file):
         '''Merge two pcap files to pcapng, "any" merge mode'''
         # $MERGECAP -vI 'any' -w testout.pcap "${CAPTURE_DIR}dhcp.pcap" "${CAPTURE_DIR}dhcp.pcap" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-I', 'any',
             '-w', testout_file,
-            dhcp_pcap, dhcp_pcap,
+            capture_file('dhcp.pcap'), capture_file('dhcp.pcap'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Ethernet', 8, 1, 8)
 
-    def test_mergecap_basic_1_pcapng_pcapng(self):
+    def test_mergecap_basic_1_pcapng_pcapng(self, cmd_mergecap, capture_file):
         '''Merge a single pcapng file to pcapng'''
         # $MERGECAP -v -w testout.pcap "${CAPTURE_DIR}dhcp.pcapng" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-w', testout_file,
-            dhcp_pcapng,
+            capture_file('dhcp.pcapng'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Ethernet', 4, 1, 4)
 
-    def test_mergecap_1_pcapng_many_pcapng(self):
+    def test_mergecap_1_pcapng_many_pcapng(self, cmd_mergecap, capture_file):
         '''Merge one pcapng file with many interfaces to pcapng'''
         # $MERGECAP -v -w testout.pcap "${CAPTURE_DIR}many_interfaces.pcapng.1" > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-w', testout_file,
-            many_interfaces_pcapng_1,
+            capture_file('many_interfaces.pcapng.1'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Per packet', 64, 11, 62)
 
-    def test_mergecap_3_pcapng_pcapng(self):
+    def test_mergecap_3_pcapng_pcapng(self, cmd_mergecap, capture_file):
         '''Merge multiple pcapng files with many interfaces to pcapng'''
         # $MERGECAP -v -w testout.pcap "${CAPTURE_DIR}"many_interfaces.pcapng* > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-w', testout_file,
-            many_interfaces_pcapng_1,
-            many_interfaces_pcapng_2,
-            many_interfaces_pcapng_3,
+            capture_file('many_interfaces.pcapng.1'),
+            capture_file('many_interfaces.pcapng.2'),
+            capture_file('many_interfaces.pcapng.3'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Per packet', 88, 11, 86)
 
-    def test_mergecap_3_pcapng_none_pcapng(self):
+    def test_mergecap_3_pcapng_none_pcapng(self, cmd_mergecap, capture_file):
         '''Merge multiple pcapng files with many interfaces to pcapng, "none" merge mode'''
         # $MERGECAP -vI 'none' -w testout.pcap "${CAPTURE_DIR}"many_interfaces.pcapng* > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-I', 'none',
             '-w', testout_file,
-            many_interfaces_pcapng_1,
-            many_interfaces_pcapng_2,
-            many_interfaces_pcapng_3,
+            capture_file('many_interfaces.pcapng.1'),
+            capture_file('many_interfaces.pcapng.2'),
+            capture_file('many_interfaces.pcapng.3'),
         ))
         check_mergecap(self, mergecap_proc, 'pcapng', 'Per packet', 88, 33, 62)
 
-    def test_mergecap_3_pcapng_all_pcapng(self):
+    def test_mergecap_3_pcapng_all_pcapng(self, cmd_mergecap, capture_file):
         '''Merge multiple pcapng files to pcapng in "none" mode, then merge that to "all" mode.'''
         # build a pcapng of all the interfaces repeated by using mode 'none'
         # $MERGECAP -vI 'none' -w testin.pcap "${CAPTURE_DIR}"many_interfaces.pcapng* > testout.txt 2>&1
         testin_file = self.filename_from_id('testin.pcapng')
-        self.assertRun((config.cmd_mergecap,
+        self.assertRun((cmd_mergecap,
             '-v',
             '-I', 'none',
             '-w', testin_file,
-            many_interfaces_pcapng_1,
-            many_interfaces_pcapng_2,
-            many_interfaces_pcapng_3,
+            capture_file('many_interfaces.pcapng.1'),
+            capture_file('many_interfaces.pcapng.2'),
+            capture_file('many_interfaces.pcapng.3'),
         ))
         # the above generated 33 IDBs, 88 total pkts, 62 in first IDB
 
         # and use that generated pcap for our test
         # $MERGECAP -vI 'all' -w testout.pcap ./testin.pcap ./testin.pcap ./testin.pcap > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-I', 'all',
             '-w', testout_file,
@@ -264,25 +260,25 @@ class case_mergecap_pcapng(subprocesstest.SubprocessTestCase):
         # check for 33 IDBs, 88*3=264 total pkts, 62*3=186 in first IDB
         check_mergecap(self, mergecap_proc, 'pcapng', 'Per packet', 264, 33, 186)
 
-    def test_mergecap_3_pcapng_any_pcapng(self):
+    def test_mergecap_3_pcapng_any_pcapng(self, cmd_mergecap, capture_file):
         '''Merge multiple pcapng files to pcapng in "none" mode, then merge that to "all" mode.'''
         # build a pcapng of all the interfaces repeated by using mode 'none'
         # $MERGECAP -vI 'none' -w testin.pcap "${CAPTURE_DIR}"many_interfaces.pcapng* > testout.txt 2>&1
         testin_file = self.filename_from_id('testin.pcapng')
-        self.assertRun((config.cmd_mergecap,
+        self.assertRun((cmd_mergecap,
             '-v',
             '-I', 'none',
             '-w', testin_file,
-            many_interfaces_pcapng_1,
-            many_interfaces_pcapng_2,
-            many_interfaces_pcapng_3,
+            capture_file('many_interfaces.pcapng.1'),
+            capture_file('many_interfaces.pcapng.2'),
+            capture_file('many_interfaces.pcapng.3'),
         ))
         # the above generated 33 IDBs, 88 total pkts, 62 in first IDB
 
         # and use that generated pcap for our test
         # $MERGECAP -vI 'any' -w testout.pcap ./testin.pcap ./testin.pcap ./testin.pcap > testout.txt 2>&1
         testout_file = self.filename_from_id(testout_pcapng)
-        mergecap_proc = self.runProcess((config.cmd_mergecap,
+        mergecap_proc = self.runProcess((cmd_mergecap,
             '-v',
             '-I', 'any',
             '-w', testout_file,
@@ -290,4 +286,3 @@ class case_mergecap_pcapng(subprocesstest.SubprocessTestCase):
         ))
         # check for 11 IDBs, 88*3=264 total pkts, 86*3=258 in first IDB
         check_mergecap(self, mergecap_proc, 'pcapng', 'Per packet', 264, 11, 258)
-
index 64cba38aecf9316d605bf8cf21b281d9f209a772..e69fdf56d89b08a85fc1e933fb1500c9c4cc201f 100644 (file)
@@ -7,20 +7,23 @@
 #
 '''sharkd tests'''
 
-import config
 import json
-import os.path
 import subprocess
 import subprocesstest
-import sys
-import unittest
+import fixtures
 
-dhcp_pcap = os.path.join(config.capture_dir, 'dhcp.pcap')
 
+@fixtures.fixture(scope='session')
+def cmd_sharkd(program):
+    return program('sharkd')
+
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_sharkd(subprocesstest.SubprocessTestCase):
-    def test_sharkd_hello_no_pcap(self):
+    def test_sharkd_hello_no_pcap(self, cmd_sharkd):
         '''sharkd hello message, no capture file'''
-        sharkd_proc = self.startProcess((config.cmd_sharkd, '-'),
+        sharkd_proc = self.startProcess((cmd_sharkd, '-'),
             stdin=subprocess.PIPE
         )
 
@@ -36,14 +39,14 @@ class case_sharkd(subprocesstest.SubprocessTestCase):
         except:
             self.fail('Invalid JSON: "{}"'.format(sharkd_proc.stdout_str))
 
-    def test_sharkd_hello_dhcp_pcap(self):
+    def test_sharkd_hello_dhcp_pcap(self, cmd_sharkd, capture_file):
         '''sharkd hello message, simple capture file'''
-        sharkd_proc = self.startProcess((config.cmd_sharkd, '-'),
+        sharkd_proc = self.startProcess((cmd_sharkd, '-'),
             stdin=subprocess.PIPE
         )
 
         sharkd_commands = b'{"req":"load","file":'
-        sharkd_commands += json.dumps(dhcp_pcap).encode('utf8')
+        sharkd_commands += json.dumps(capture_file('dhcp.pcap')).encode('utf8')
         sharkd_commands += b'}\n'
         sharkd_commands += b'{"req":"status"}\n'
         sharkd_commands += b'{"req":"frames"}\n'
index 1233807a10b1dab03732fee89160a009e0a43e38..94621ed7fa33400b7e3d04703a86f0de03c0f0ab 100644 (file)
 import config
 import difflib
 import os.path
-import pprint
 import re
 import subprocesstest
-import unittest
+import fixtures
 
+
+@fixtures.uses_fixtures
 class case_unittests(subprocesstest.SubprocessTestCase):
-    def test_unit_exntest(self):
+    def test_unit_exntest(self, program, base_env):
         '''exntest'''
-        self.assertRun(os.path.join(config.program_path, 'exntest'))
+        self.assertRun(program('exntest'), env=base_env)
 
-    def test_unit_oids_test(self):
+    def test_unit_oids_test(self, program, base_env):
         '''oids_test'''
-        self.assertRun(os.path.join(config.program_path, 'oids_test'))
+        self.assertRun(program('oids_test'), env=base_env)
 
-    def test_unit_reassemble_test(self):
+    def test_unit_reassemble_test(self, program, base_env):
         '''reassemble_test'''
-        self.assertRun(os.path.join(config.program_path, 'reassemble_test'))
+        self.assertRun(program('reassemble_test'), env=base_env)
 
-    def test_unit_tvbtest(self):
+    def test_unit_tvbtest(self, program, base_env):
         '''tvbtest'''
-        self.assertRun(os.path.join(config.program_path, 'tvbtest'))
+        self.assertRun(program('tvbtest'), env=base_env)
 
-    def test_unit_wmem_test(self):
+    def test_unit_wmem_test(self, program, base_env):
         '''wmem_test'''
-        self.assertRun((os.path.join(config.program_path, 'wmem_test'),
+        self.assertRun((program('wmem_test'),
             '--verbose'
-        ))
+        ), env=base_env)
 
-    def test_unit_wmem_test(self):
+    def test_unit_wmem_test(self, program, base_env):
         '''wmem_test'''
-        self.assertRun((os.path.join(config.program_path, 'wmem_test'),
+        self.assertRun((program('wmem_test'),
             '--verbose'
-        ))
+        ), env=base_env)
 
-    def test_unit_fieldcount(self):
+    def test_unit_fieldcount(self, cmd_tshark, test_env):
         '''fieldcount'''
-        self.assertRun((config.cmd_tshark, '-G', 'fieldcount'))
+        self.assertRun((cmd_tshark, '-G', 'fieldcount'), env=test_env)
 
     def test_unit_ctest_coverage(self):
         '''Make sure CTest runs all of our tests.'''
-        with open(os.path.join(config.this_dir, '..', 'CMakeLists.txt')) as cml_fd:
-            group_re = re.compile('set *\( *_test_group_list')
+        with open(os.path.join(os.path.dirname(__file__), '..', 'CMakeLists.txt')) as cml_fd:
+            group_re = re.compile(r'set *\( *_test_group_list')
             in_list = False
             cml_groups = []
             for cml_line in cml_fd:
@@ -95,10 +96,12 @@ class Field:
         self.bitmask = int(data[6],0)
         self.blurb = data[7]
 
+
+@fixtures.uses_fixtures
 class case_unit_ftsanity(subprocesstest.SubprocessTestCase):
-    def test_unit_ftsanity(self):
+    def test_unit_ftsanity(self, cmd_tshark, base_env):
         """Looks for problems in field type definitions."""
-        tshark_proc = self.assertRun((config.cmd_tshark, "-G", "fields"))
+        tshark_proc = self.assertRun((cmd_tshark, "-G", "fields"), env=base_env)
 
         lines = tshark_proc.stdout_str.splitlines()
         # XXX We don't currently check protos.
index d2982a4887b65f94f6b97146f0f07af8ce54fe7d..a48f75d5961ca5508677700c3a18503d5bf0a748 100644 (file)
@@ -9,12 +9,11 @@
 #
 '''Wireshark Lua scripting tests'''
 
-import config
 import filecmp
-import io
 import os.path
 import subprocesstest
 import unittest
+import fixtures
 
 dhcp_pcap = 'dhcp.pcap'
 dns_port_pcap = 'dns_port.pcap'
@@ -24,70 +23,80 @@ sip_pcapng = 'sip.pcapng'
 sipmsg_log = 'sipmsg.log'
 wpa_induction_pcap_gz = 'wpa-Induction.pcap.gz'
 
-def check_lua_script(self, lua_script, cap_file, check_passed, *args):
-    if not config.have_lua:
-        self.skipTest('Test requires Lua scripting support.')
-    tshark_cmd = [config.cmd_tshark,
-        '-r', os.path.join(config.capture_dir, cap_file),
-        '-X', 'lua_script:' + os.path.join(config.lua_dir, lua_script)
-    ]
-    tshark_cmd += args
-    tshark_proc = self.assertRun(tshark_cmd)
-
-    if check_passed:
-        self.assertTrue(self.grepOutput(r'All tests passed!'))
-
-    return tshark_proc
-
-def check_lua_script_verify(self, lua_script, cap_file, check_stage_1=False, heur_regmode=None):
-    # First run tshark with the dissector script.
-    if heur_regmode is None:
-        tshark_proc = check_lua_script(self, lua_script, dns_port_pcap, check_stage_1,
-            '-V'
-        )
-    else:
-        tshark_proc = check_lua_script(self, lua_script, dns_port_pcap, check_stage_1,
-            '-V',
-            '-X', 'lua_script1:heur_regmode={}'.format(heur_regmode)
-        )
-
-    # then dump tshark's output to a verification file.
-    verify_file = self.filename_from_id('testin.txt')
-    with io.open(verify_file, 'w', newline='\n') as testin_fd:
-        testin_fd.write(tshark_proc.stdout_str)
-        testin_fd.close()
-
-    # finally run tshark again with the verification script and the verification file.
-    if heur_regmode is None:
-        check_lua_script(self, 'verify_dissector.lua', empty_pcap, True,
-            '-X', 'lua_script1:verify_file=' + verify_file,
-        )
-    else:
-        check_lua_script(self, 'verify_dissector.lua', empty_pcap, True,
-            '-X', 'lua_script1:verify_file=' + verify_file,
-            '-X', 'lua_script1:no_heur',
-        )
 
+@fixtures.fixture(scope='session')
+def check_lua_script(cmd_tshark, features, dirs, capture_file):
+    if not features.have_lua:
+        self.skipTest('Test requires Lua scripting support.')
+    def check_lua_script_real(self, lua_script, cap_file, check_passed, *args):
+        tshark_cmd = [cmd_tshark,
+            '-r', capture_file(cap_file),
+            '-X', 'lua_script:' + os.path.join(dirs.lua_dir, lua_script)
+        ]
+        tshark_cmd += args
+        tshark_proc = self.assertRun(tshark_cmd)
+
+        if check_passed:
+            self.assertIn('All tests passed!', tshark_proc.stdout_str)
+
+        return tshark_proc
+    return check_lua_script_real
+
+
+@fixtures.fixture(scope='session')
+def check_lua_script_verify(check_lua_script):
+    def check_lua_script_verify_real(self, lua_script, cap_file, check_stage_1=False, heur_regmode=None):
+        # First run tshark with the dissector script.
+        if heur_regmode is None:
+            tshark_proc = check_lua_script(self, lua_script, dns_port_pcap, check_stage_1,
+                '-V'
+            )
+        else:
+            tshark_proc = check_lua_script(self, lua_script, dns_port_pcap, check_stage_1,
+                '-V',
+                '-X', 'lua_script1:heur_regmode={}'.format(heur_regmode)
+            )
+
+        # then dump tshark's output to a verification file.
+        verify_file = self.filename_from_id('testin.txt')
+        with open(verify_file, 'w', newline='\n') as f:
+            f.write(tshark_proc.stdout_str)
+
+        # finally run tshark again with the verification script and the verification file.
+        if heur_regmode is None:
+            check_lua_script(self, 'verify_dissector.lua', empty_pcap, True,
+                '-X', 'lua_script1:verify_file=' + verify_file,
+            )
+        else:
+            check_lua_script(self, 'verify_dissector.lua', empty_pcap, True,
+                '-X', 'lua_script1:verify_file=' + verify_file,
+                '-X', 'lua_script1:no_heur',
+            )
+    return check_lua_script_verify_real
+
+
+@fixtures.mark_usefixtures('test_env')
+@fixtures.uses_fixtures
 class case_wslua(subprocesstest.SubprocessTestCase):
-    def test_wslua_dir(self):
+    def test_wslua_dir(self, check_lua_script):
         '''wslua directory functions'''
         check_lua_script(self, 'dir.lua', empty_pcap, True)
 
     # Mode_1, mode_2, and mode_3, and fpm were all under wslua_step_dissector_test
     # in the Bash version.
-    def test_wslua_dissector_mode_1(self):
+    def test_wslua_dissector_mode_1(self, check_lua_script_verify):
         '''wslua dissector functions, mode 1'''
         check_lua_script_verify(self, 'dissector.lua', dns_port_pcap)
 
-    def test_wslua_dissector_mode_2(self):
+    def test_wslua_dissector_mode_2(self, check_lua_script_verify):
         '''wslua dissector functions, mode 2'''
         check_lua_script_verify(self, 'dissector.lua', dns_port_pcap, heur_regmode=2)
 
-    def test_wslua_dissector_mode_3(self):
+    def test_wslua_dissector_mode_3(self, check_lua_script_verify):
         '''wslua dissector functions, mode 3'''
         check_lua_script_verify(self, 'dissector.lua', dns_port_pcap, heur_regmode=3)
 
-    def test_wslua_dissector_fpm(self):
+    def test_wslua_dissector_fpm(self, check_lua_script):
         '''wslua dissector functions, fpm'''
         tshark_fpm_tcp_proc = check_lua_script(self, 'dissectFPM.lua', segmented_fpm_pcap, False,
             '-T', 'fields',
@@ -115,16 +124,16 @@ class case_wslua(subprocesstest.SubprocessTestCase):
             'fpm.dissect_tcp:false',
         )
 
-    def test_wslua_field(self):
+    def test_wslua_field(self, check_lua_script):
         '''wslua fields'''
         check_lua_script(self, 'field.lua', dhcp_pcap, True)
 
     # reader, writer, and acme_reader were all under wslua_step_file_test
     # in the Bash version.
-    def test_wslua_file_reader(self):
+    def test_wslua_file_reader(self, check_lua_script, cmd_tshark, capture_file):
         '''wslua file reader'''
-        cap_file_1 = os.path.join(config.capture_dir, dhcp_pcap)
-        cap_file_2 = os.path.join(config.capture_dir, wpa_induction_pcap_gz)
+        cap_file_1 = capture_file(dhcp_pcap)
+        cap_file_2 = capture_file(wpa_induction_pcap_gz)
 
         # First run tshark with the pcap_file_reader script.
         lua_proc_1 = check_lua_script(self, 'pcap_file.lua', cap_file_1, False)
@@ -132,15 +141,15 @@ class case_wslua(subprocesstest.SubprocessTestCase):
         lua_out = lua_proc_1.stdout_str + lua_proc_2.stdout_str
 
         # then run tshark again without the script
-        tshark_proc_1 = self.assertRun((config.cmd_tshark, '-r', cap_file_1))
-        tshark_proc_2 = self.assertRun((config.cmd_tshark, '-r', cap_file_2))
+        tshark_proc_1 = self.assertRun((cmd_tshark, '-r', cap_file_1))
+        tshark_proc_2 = self.assertRun((cmd_tshark, '-r', cap_file_2))
         tshark_out = tshark_proc_1.stdout_str + tshark_proc_2.stdout_str
 
         self.diffOutput(lua_out, tshark_out, 'tshark + lua script', 'tshark only')
 
-    def test_wslua_file_writer(self):
+    def test_wslua_file_writer(self, check_lua_script, capture_file):
         '''wslua file writer'''
-        cap_file_1 = os.path.join(config.capture_dir, dhcp_pcap)
+        cap_file_1 = capture_file(dhcp_pcap)
         cap_file_2 = self.filename_from_id('lua_writer.pcap')
 
         # Generate a new capture file using the Lua writer.
@@ -150,7 +159,7 @@ class case_wslua(subprocesstest.SubprocessTestCase):
         )
         self.assertTrue(filecmp.cmp(cap_file_1, cap_file_2), cap_file_1 + ' differs from ' + cap_file_2)
 
-    def test_wslua_file_acme_reader(self):
+    def test_wslua_file_acme_reader(self, check_lua_script, cmd_tshark, capture_file):
         '''wslua acme file reader'''
 
         cap_file = self.filename_from_id('lua_acme_reader.pcap')
@@ -161,56 +170,56 @@ class case_wslua(subprocesstest.SubprocessTestCase):
         )
 
         # Read lua_acme_reader.pcap and sip.pcapng and compare their verbose outputs.
-        tshark_proc_1 = self.assertRun((config.cmd_tshark,
+        tshark_proc_1 = self.assertRun((cmd_tshark,
             '-r', cap_file,
             '-V'
         ))
-        tshark_proc_2 = self.assertRun((config.cmd_tshark,
-            '-r', os.path.join(config.capture_dir, sip_pcapng),
+        tshark_proc_2 = self.assertRun((cmd_tshark,
+            '-r', capture_file(sip_pcapng),
             '-V'
         ))
         self.diffOutput(tshark_proc_1.stdout_str, tshark_proc_2.stdout_str, 'sipmsg.log', 'sip.pcapng')
 
-    def test_wslua_listener(self):
+    def test_wslua_listener(self, check_lua_script):
         '''wslua listener'''
         check_lua_script(self, 'listener.lua', dhcp_pcap, True)
 
-    def test_wslua_nstime(self):
+    def test_wslua_nstime(self, check_lua_script):
         '''wslua nstime'''
         check_lua_script(self, 'nstime.lua', dhcp_pcap, True)
 
-    def test_wslua_pinfo(self):
+    def test_wslua_pinfo(self, check_lua_script):
         '''wslua pinfo'''
         check_lua_script(self, 'pinfo.lua', dhcp_pcap, True)
 
-    def test_wslua_proto(self):
+    def test_wslua_proto(self, check_lua_script_verify):
         '''wslua proto'''
         check_lua_script_verify(self, 'proto.lua', dns_port_pcap, check_stage_1=True)
 
-    def test_wslua_protofield_tree(self):
+    def test_wslua_protofield_tree(self, check_lua_script):
         '''wslua protofield with a tree'''
         check_lua_script(self, 'protofield.lua', dns_port_pcap, True,
             '-V',
             '-Y', 'test.filtered==1',
         )
 
-    def test_wslua_protofield_no_tree(self):
+    def test_wslua_protofield_no_tree(self, check_lua_script):
         '''wslua protofield without a tree'''
         check_lua_script(self, 'protofield.lua', dns_port_pcap, True,
             '-Y', 'test.filtered==1',
         )
 
-    def test_wslua_int64(self):
+    def test_wslua_int64(self, check_lua_script):
         '''wslua int64'''
         check_lua_script(self, 'int64.lua', empty_pcap, True)
 
-    def test_wslua_args_1(self):
+    def test_wslua_args_1(self, check_lua_script):
         '''wslua args 1'''
         check_lua_script(self, 'script_args.lua', empty_pcap, True,
             '-X', 'lua_script1:1',
         )
 
-    def test_wslua_args_2(self):
+    def test_wslua_args_2(self, check_lua_script):
         '''wslua args 2'''
         check_lua_script(self, 'script_args.lua', empty_pcap, True,
             '-X', 'lua_script1:3',
@@ -218,52 +227,52 @@ class case_wslua(subprocesstest.SubprocessTestCase):
             '-X', 'lua_script1:bar',
         )
 
-    def test_wslua_args_3(self):
+    def test_wslua_args_3(self, check_lua_script, dirs):
         '''wslua args 3'''
         check_lua_script(self, 'script_args.lua', empty_pcap, True,
-            '-X', 'lua_script:' + os.path.join(config.lua_dir, 'script_args.lua'),
+            '-X', 'lua_script:' + os.path.join(dirs.lua_dir, 'script_args.lua'),
             '-X', 'lua_script1:3',
             '-X', 'lua_script2:1',
             '-X', 'lua_script1:foo',
             '-X', 'lua_script1:bar',
         )
 
-    def test_wslua_args_4(self):
+    def test_wslua_args_4(self, check_lua_script):
         '''wslua args 4'''
         check_lua_script(self, 'script_args.lua', empty_pcap, False)
         self.assertFalse(self.grepOutput(r'All tests passed!'))
 
-    def test_wslua_args_5(self):
+    def test_wslua_args_5(self, check_lua_script):
         '''wslua args 5'''
         check_lua_script(self, 'script_args.lua', empty_pcap, False,
             '-X', 'lua_script1:3',
         )
         self.assertFalse(self.grepOutput(r'All tests passed!'))
 
-    def test_wslua_globals(self):
+    def test_wslua_globals(self, check_lua_script, dirs):
         '''wslua globals'''
         check_lua_script(self, 'verify_globals.lua', empty_pcap, True,
-            '-X', 'lua_script1:' + os.path.join(config.lua_dir, ''),
-            '-X', 'lua_script1:' + os.path.join(config.lua_dir, 'globals_2.2.txt'),
+            '-X', 'lua_script1:' + os.path.join(dirs.lua_dir, ''),
+            '-X', 'lua_script1:' + os.path.join(dirs.lua_dir, 'globals_2.2.txt'),
         )
 
     @unittest.skip('GRegex tests are broken since PCRE 8.34, see bug 12997.')
-    def test_wslua_gregex(self):
+    def test_wslua_gregex(self, check_lua_script, dirs):
         '''wslua GRegex'''
         check_lua_script(self, 'gregex.lua', empty_pcap, True,
-            '-X', 'lua_script1:' + os.path.join(config.lua_dir, ''),
+            '-X', 'lua_script1:' + os.path.join(dirs.lua_dir, ''),
             '-X', 'lua_script1:glib',
             '-X', 'lua_script1:-V',
         )
 
-    def test_wslua_struct(self):
+    def test_wslua_struct(self, check_lua_script):
         '''wslua struct'''
         check_lua_script(self, 'struct.lua', empty_pcap, True)
 
-    def test_wslua_tvb_tree(self):
+    def test_wslua_tvb_tree(self, check_lua_script):
         '''wslua tvb with a tree'''
         check_lua_script(self, 'tvb.lua', dns_port_pcap, True, '-V')
 
-    def test_wslua_tvb_no_tree(self):
+    def test_wslua_tvb_no_tree(self, check_lua_script):
         '''wslua tvb without a tree'''
         check_lua_script(self, 'tvb.lua', dns_port_pcap, True)