Skip to content

Update python test suite to use pytest rather than nose#187

Open
mpenny-github wants to merge 22 commits into
masterfrom
use_pytest
Open

Update python test suite to use pytest rather than nose#187
mpenny-github wants to merge 22 commits into
masterfrom
use_pytest

Conversation

@mpenny-github
Copy link
Copy Markdown
Contributor

@mpenny-github mpenny-github commented May 20, 2026

This is the third PR in a series to add support for running glb-director on ubuntu noble.
Previous PR: https://github.com/github/glb-director/pull/186/changes

It's a semi-optional pull request. The existing testing framework is functional for ubuntu focal, but it's based upon nose test library which are end of life. It won't be compatible with the version of python that ships with ubuntu noble.

There is a replacement library nose2 (https://github.com/nose-devs/nose2), but it doesn't support the older python the will come with ubuntu focal. Rather then trying to run the two tests in parallel, it made more sense to use pytest, which is supported on both platforms. The syntax is nearly identical, which allows for a relatively simple replacements.

@mpenny-github mpenny-github marked this pull request as ready for review May 27, 2026 19:31
Copilot AI review requested due to automatic review settings May 27, 2026 19:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the repository’s Python-based test suites from the EOL nose framework to pytest to keep tests runnable on newer Ubuntu/Python versions (notably Ubuntu Noble), while also improving local/CI ergonomics for environments that lack required kernel/network infrastructure.

Changes:

  • Replace nose assertions/attributes with pytest idioms (plain assert, pytest.mark.*) across glb-director and glb-redirect tests.
  • Add pytest marker configuration (pytest.ini) and update test runner scripts to select DPDK vs XDP tests via markers.
  • Improve containerized/local test behavior by adding skip mechanisms for missing infrastructure (e.g., vagrant backends, hugepages, KNI, XDP attach) and add/adjust CI + Docker image dependencies.
Show a summary per file
File Description
src/scapy-glb-gue/glb_scapy/glb_gue_scapy.py Fix integer division for header length calculation under Py3.
src/scapy-glb-gue/glb_scapy/init.py Use relative import for package correctness.
src/glb-redirect/tests/test_glb_redirect_v6_on_v4.py Convert assertions/prints from nose/Py2 style to pytest/Py3 style.
src/glb-redirect/tests/test_glb_redirect_v4_on_v4.py Convert assertions/prints from nose/Py2 style to pytest/Py3 style.
src/glb-redirect/tests/glb_test_utils.py Add pytest-compatible skipping when vagrant backend network is unavailable.
src/glb-redirect/tests/glb_test_remote_snoop.py Minor Py3 print adjustment for debug output.
src/glb-redirect/script/test Switch test runner from nosetests to pytest.
src/glb-redirect/pytest.ini Define runtime markers for selecting DPDK vs XDP tests.
src/glb-healthcheck/test/test-basic.sh Add conditional skips for missing vagrant backends; use python3 http server.
src/glb-healthcheck/test/lib.sh Add a skip mechanism and a backend reachability probe; bind local backend IP in docker.
src/glb-director/tests/test-config.json Reformat test config JSON (ordering/whitespace) for Py3-era tooling usage.
src/glb-director/tests/test_rendezvous_table.py Replace Py2 hex encode/decode + nose asserts with Py3/pytest style.
src/glb-director/tests/test_director_metrics.py Convert nose attrs to pytest markers for backend selection.
src/glb-director/tests/test_director_kni.py Convert nose attrs/asserts to pytest markers/asserts.
src/glb-director/tests/test_director_hash_fields.py Convert nose asserts to pytest-style asserts.
src/glb-director/tests/test_director_classify_v6.py Convert nose asserts to pytest-style asserts; update prints.
src/glb-director/tests/test_director_classify_v4.py Convert nose asserts to pytest-style asserts.
src/glb-director/tests/test_director_classify_ranges_v6.py Convert nose attrs/asserts to pytest markers/asserts.
src/glb-director/tests/test_director_classify_ranges_v4.py Convert nose asserts to pytest style; adjust SkipTest import.
src/glb-director/tests/test_cli_tool.py Convert Py2 hex/map/bytes handling and nose asserts to Py3 + pytest-style asserts.
src/glb-director/tests/pcap_tests.sh Add skips when hugepages aren’t available to avoid false failures.
src/glb-director/tests/lib/testlib.sh Add a skip mechanism and hugepage availability detection.
src/glb-director/tests/glb_test_utils.py Add runtime/environment probes to skip incompatible setups; improve Py3 byte/string handling.
src/glb-director/script/test Switch test runner from nosetests to pytest with marker-based selection.
src/glb-director/pytest.ini Define runtime markers for selecting DPDK vs XDP tests.
src/glb-director-xdp/script/test Run glb-director pytest suite under XDP mode using marker filtering.
script/test-local Add local helper to build per-distro images and run all suite scripts in containers.
script/helpers/folding.sh Update fold output to GitHub Actions log grouping syntax.
script/Dockerfile.focal Pin base image digest; add python/pytest deps and GOFLAGS -buildvcs=false for container builds.
script/cibuild-create-packages-focal Remove focal-only package build script (replaced by parameterized script).
script/cibuild-create-packages Parameterize package build by distro and update docker build invocation.
requirements.txt Replace nose dependency with pytest version range.
.github/workflows/test.yml Add workflow to build docker images and run each suite in a privileged container.
.github/workflows/ci.yml Update package-build job to use parameterized package script and distro matrix.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

src/glb-director/tests/glb_test_utils.py:232

  • stdout=open('director-output.txt', 'ab') leaves a file handle open in the parent process. Use a with open(...): around Popen(...) (or close the file object right after spawning) to avoid leaking file descriptors, especially since XDP tests can relaunch the director during reloads.
	def setup(self, iface):
		notify_shim = SystemdNotify('/tmp/glb-notify-shim.sock')
		self.xdp_root = subprocess.Popen(
			[
				'../glb-director-xdp/xdp-root-shim/xdp-root-shim',
				os.path.abspath('../glb-director-xdp/bpf/tailcall.o'),
				'/sys/fs/bpf/root_array@' + iface,
				iface,
			],
			stdout=open('director-output.txt', 'ab'),
			stderr=subprocess.STDOUT,
			env=notify_shim.updated_env(),
		)
		notify_shim.wait()
  • Files reviewed: 33/34 changed files
  • Comments generated: 4

Comment thread src/glb-redirect/tests/glb_test_utils.py
Comment thread src/glb-director/tests/glb_test_utils.py
Comment thread src/glb-director/tests/glb_test_utils.py
Comment thread src/glb-director/tests/glb_test_utils.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants