13.5. External Tests

You can create your own Python test files outside of the Wireshark source tree. To include your tests when running the Wireshark test suite, simply add the directory containing your test files to the pytest command line. Note that filenames must match the same conventions as discussed above.

In order for your tests to have access to the Wireshark test fixtures, you will need this line in each test file:

from fixtures_ws import *

13.5.1. Custom Fixtures

You may wish to define your own test fixtures — for example, a fixture similar to capture_file but which gives the path to a file in your external test directory. Here is an example Python file containing such a fixture. It presumes a subdirectory named extra_captures which exists in the same directory, and which contains your extra capture files.

# my_fixtures.py
# To use in your own tests, import like so:
#   from my_fixtures import *

from pathlib import Path
import pytest

@pytest.fixture(scope='session')
def extra_file():
    def resolver(filename):
        return Path(__file__).parent.joinpath("extra_captures", filename)
    return resolver
[Note]Note

If you give your fixture the same name as an existing Wireshark fixture, any tests using your fixture library will lose access to the Wireshark fixture of the same name. This can lead to confusing behavior and is not recommended.