aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite_clopts.py
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2023-05-08 07:32:58 +0100
committerGerald Combs <gerald@wireshark.org>2023-05-10 18:53:31 +0000
commit3128269aa0ef04c7537e6dec958b491eb76cb0ff (patch)
treeb3a4d3fe1f48363cd3b0b0939c215a6e6b6f0b05 /test/suite_clopts.py
parent99f059c48b98746fa581b721eb0e9b1a99e57dcb (diff)
Tests: Require pytest support and remove compatibility layer
Remove the pytest compatibility layer and require the real thing. Fix running tests with pytest and Python 3.11+. Pytest strongly favors using fixtures instead of setup/teardown methods so use that. This fixes the test suite with pytest and Python 3.11 and has the added benefit of removing the dependency on a private unittest property. We remove the dedicated log file code in SubprocessTestCase and just write to standard out. This presumes to leverage the pytest logging features, such as writing to a log file. To make the system more useful we should probably rely on logging calls instead of writing to stdout. The teardown log file cleanup logic and filename_from_id() method are replaced with pytest fixtures and native temporary path support. They are cleaner to use and do not require messy teadown logic. The temporary files are created in the system temporary directory. By default the last three runs are kept. More work is needed to complete remove the unittest module dependency. Fixes #18740.
Diffstat (limited to 'test/suite_clopts.py')
-rw-r--r--test/suite_clopts.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/test/suite_clopts.py b/test/suite_clopts.py
index 7b16af3f93..1150ff311d 100644
--- a/test/suite_clopts.py
+++ b/test/suite_clopts.py
@@ -48,27 +48,27 @@ class case_dumpcap_options(subprocesstest.SubprocessTestCase):
@fixtures.mark_usefixtures('base_env')
@fixtures.uses_fixtures
class case_dumpcap_capture_clopts(subprocesstest.SubprocessTestCase):
- def test_dumpcap_invalid_capfilter(self, cmd_dumpcap, capture_interface):
+ def test_dumpcap_invalid_capfilter(self, cmd_dumpcap, capture_interface, result_file):
'''Invalid capture filter'''
invalid_filter = '__invalid_protocol'
# $DUMPCAP -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
- testout_file = self.filename_from_id(testout_pcap)
+ testout_file = result_file(testout_pcap)
self.runProcess((cmd_dumpcap, '-f', invalid_filter, '-w', testout_file))
self.assertTrue(self.grepOutput('Invalid capture filter "' + invalid_filter + '" for interface'))
- def test_dumpcap_invalid_interface_name(self, cmd_dumpcap, capture_interface):
+ def test_dumpcap_invalid_interface_name(self, cmd_dumpcap, capture_interface, result_file):
'''Invalid capture interface name'''
invalid_interface = '__invalid_interface'
# $DUMPCAP -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
- testout_file = self.filename_from_id(testout_pcap)
+ testout_file = result_file(testout_pcap)
self.runProcess((cmd_dumpcap, '-i', invalid_interface, '-w', testout_file))
self.assertTrue(self.grepOutput('There is no device named "__invalid_interface"'))
- def test_dumpcap_invalid_interface_index(self, cmd_dumpcap, capture_interface):
+ def test_dumpcap_invalid_interface_index(self, cmd_dumpcap, capture_interface, result_file):
'''Invalid capture interface index'''
invalid_index = '0'
# $DUMPCAP -i 0 -w './testout.pcap' > ./testout.txt 2>&1
- testout_file = self.filename_from_id(testout_pcap)
+ testout_file = result_file(testout_pcap)
self.runProcess((cmd_dumpcap, '-i', invalid_index, '-w', testout_file))
self.assertTrue(self.grepOutput('There is no interface with that adapter index'))
@@ -114,27 +114,27 @@ class case_tshark_options(subprocesstest.SubprocessTestCase):
@fixtures.mark_usefixtures('test_env')
@fixtures.uses_fixtures
class case_tshark_capture_clopts(subprocesstest.SubprocessTestCase):
- def test_tshark_invalid_capfilter(self, cmd_tshark, capture_interface):
+ def test_tshark_invalid_capfilter(self, cmd_tshark, capture_interface, result_file):
'''Invalid capture filter'''
invalid_filter = '__invalid_protocol'
# $TSHARK -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
- testout_file = self.filename_from_id(testout_pcap)
+ testout_file = result_file(testout_pcap)
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, cmd_tshark, capture_interface):
+ def test_tshark_invalid_interface_name(self, cmd_tshark, capture_interface, result_file):
'''Invalid capture interface name'''
invalid_interface = '__invalid_interface'
# $TSHARK -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
- testout_file = self.filename_from_id(testout_pcap)
+ testout_file = result_file(testout_pcap)
self.runProcess((cmd_tshark, '-i', invalid_interface, '-w', testout_file))
self.assertTrue(self.grepOutput('There is no device named "__invalid_interface"'))
- def test_tshark_invalid_interface_index(self, cmd_tshark, capture_interface):
+ def test_tshark_invalid_interface_index(self, cmd_tshark, capture_interface, result_file):
'''Invalid capture interface index'''
invalid_index = '0'
# $TSHARK -i 0 -w './testout.pcap' > ./testout.txt 2>&1
- testout_file = self.filename_from_id(testout_pcap)
+ testout_file = result_file(testout_pcap)
self.runProcess((cmd_tshark, '-i', invalid_index, '-w', testout_file))
self.assertTrue(self.grepOutput('There is no interface with that adapter index'))