Skip to content

test_getting_packet_summary fails randomly #747

Description

@bmwiedemann

Describe the bug
While working on reproducible builds for openSUSE, I found that
when building python-pyshark-0.6 the test test_getting_packet_summary would fail randomly.

To Reproduce

osc checkout openSUSE:Factory/python-pyshark && cd $_
for i in $(seq 1 10) ; do osc build --vm-type=kvm --noservice -j1 standard || break ; done

Expected behavior
Tests should always succeed

Versions (please complete the following information):

  • OS: Linux / openSUSE-Tumbleweed-20260209
  • pyshark version: 0.6
  • tshark version: ?

build log

=================================== FAILURES ===================================
_________________________ test_getting_packet_summary __________________________

self = <FileCapture /home/abuild/rpmbuild/BUILD/python-pyshark-0.6-build/pyshark-0.6/tests/data/capture_test.pcapng>
packet_index = 0

    def __getitem__(self, packet_index):
        if not self.keep_packets:
            raise NotImplementedError("Cannot use getitem if packets are not kept")
            # We may not yet have this packet
        while packet_index >= len(self._packets):
            try:
>               self.next()

../../BUILDROOT/usr/lib/python3.11/site-packages/pyshark/capture/file_capture.py:72:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <FileCapture /home/abuild/rpmbuild/BUILD/python-pyshark-0.6-build/pyshark-0.6/tests/data/capture_test.pcapng>

    def next(self) -> Packet:
        """Returns the next packet in the cap.
 
        If the capture's keep_packets flag is True, will also keep it in the internal packet list.
        """
        if not self.keep_packets:
            return self._packet_generator.send(None)
        elif self._current_packet >= len(self._packets):
>           packet = self._packet_generator.send(None)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E           StopIteration

../../BUILDROOT/usr/lib/python3.11/site-packages/pyshark/capture/file_capture.py:62: StopIteration

During handling of the above exception, another exception occurred:

simple_summary_capture = <FileCapture /home/abuild/rpmbuild/BUILD/python-pyshark-0.6-build/pyshark-0.6/tests/data/capture_test.pcapng>

    def test_getting_packet_summary(simple_summary_capture):
>       assert isinstance(simple_summary_capture[0], PacketSummary)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^
                          
../tests/test_cap_operations.py:48:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <FileCapture /home/abuild/rpmbuild/BUILD/python-pyshark-0.6-build/pyshark-0.6/tests/data/capture_test.pcapng>
packet_index = 0

    def __getitem__(self, packet_index):
        if not self.keep_packets:
            raise NotImplementedError("Cannot use getitem if packets are not kept")
            # We may not yet have this packet
        while packet_index >= len(self._packets):
            try:
                self.next()
            except StopIteration:
                # We read the whole file, and there's still not such packet.
>               raise KeyError(f"Packet of index {packet_index} does not exist in capture")
E               KeyError: 'Packet of index 0 does not exist in capture'

../../BUILDROOT/usr/lib/python3.11/site-packages/pyshark/capture/file_capture.py:75: KeyError
----------------------------- Captured stdout call -----------------------------
2042-03-17 05:08:07,479 - FileCapture - DEBUG - Creating TShark subprocess with parameters: /usr/bin/tshark -l -n -T psml -r /home/abuild/rpmbuild/BUILD/python-pyshark-0.6-build/pyshark-0.6/tests/data/capture_test.pcapng
2042-03-17 05:08:07,479 - FileCapture - DEBUG - Executable: /usr/bin/tshark
2042-03-17 05:08:07,480 - FileCapture - DEBUG - TShark subprocess (pid 1930) created
2042-03-17 05:08:07,603 - FileCapture - DEBUG - EOF reached (sync)
2042-03-17 05:08:07,603 - FileCapture - DEBUG - Cleanup Subprocess (pid 1930)
--------------------------- Captured stdout teardown ---------------------------
2042-03-17 05:08:07,620 - FileCapture - DEBUG - Cleanup Subprocess (pid 1930)
=========================== short test summary info ============================
FAILED ../tests/test_cap_operations.py::test_getting_packet_summary - KeyErro...
======================== 1 failed, 65 passed in 13.89s =========================

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions