Skip to content

tests: migrate from nosetests to pytest - #1134

Merged
dimitri merged 3 commits into
mainfrom
test/pytest-migration
Jul 9, 2026
Merged

tests: migrate from nosetests to pytest#1134
dimitri merged 3 commits into
mainfrom
test/pytest-migration

Conversation

@dimitri

@dimitri dimitri commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Switch the Python test runner from nosetests to pytest. nosetests crashes on Python 3.11+ because collections.Callable was removed in Python 3.10 and nose's suite.py still references it. pytest is the modern replacement and is available in Bullseye apt as python3-pytest.

Changes

Dockerfile

  • Replace pipenv (unused) with python3-pytest in the apt install block
  • Quote 'pyroute2>=0.5.17' so the shell does not strip the >= operator

Makefile / Makefile.citus

  • NOSETESTSPYTEST = python3 -m pytest (reliable regardless of binary name; Debian's python3-pytest installs py.test-3, not pytest)
  • TEST_ARGUMENT format: nosetests --where=tests --tests=foo,bar → pytest path style tests/foo.py tests/bar.py
  • Use tests/*.py glob (not tests/) to avoid descending into tests/tablespaces/ which has its own make target and import layout
  • pytest flags: -v -s -x replace --verbose --nologcapture --nocapture --stop

tests/network.py

  • Replace universal_newlines=True with encoding='utf-8', errors='replace' in both NSPopen calls so non-ASCII bytes from pg_autoctl output are replaced rather than raising UnicodeDecodeError
  • Add LC_ALL=C LANG=C to subprocess env so PostgreSQL produces ASCII-only error messages inside network namespaces (pyroute2 ≥ 0.5.17 is strict about UTF-8 decoding)

tests/tablespaces/conftest.py (new)

  • Add project root to sys.path so tablespace tests can import as from tests.tablespaces.xxx import …; nosetests satisfied this implicitly, pytest does not

tests/pgautofailover_utils.py

  • Fix run_sql_query when autocommit=True: psycopg2's with conn: context manager wraps an implicit BEGIN even when autocommit is on, blocking DDL like CREATE TABLESPACE; use explicit commit/rollback/finally instead

.github/workflows/run-tests.yml

  • Add needs: style_checker to build_images so a style failure stops CI before any image builds start

Testing

Validated locally: TEST=single make run-test with PG17 — 88 passed, 0 failed (8 min).

dimitri added 3 commits July 9, 2026 13:53
- drop pipenv (unused)
- add python3-pytest from apt (available in bullseye at 6.0.2)
- quote 'pyroute2>=0.5.17' so the shell does not strip the >= operator
python3-nose crashes on Python 3.11+ (collections.Callable removed in
3.10; nose/suite.py still uses it).  pytest is the modern replacement
and is now installed via apt alongside python3-nose (kept for the
nose.tools helpers that a few tests still use).

Makefile changes:
- NOSETESTS → PYTEST variable using `which pytest`
- TEST_ARGUMENT format: nose --where/--tests style → pytest path style
  (tests/*.py for all, tests/foo.py for a named test)
- Use tests/*.py glob (not tests/) to avoid descending into
  tests/tablespaces/ which has its own import layout and make target

Makefile.citus: apply the same TEST_ARGUMENT pattern update that the
main Makefile received.
…ale, conftest, autocommit

1. Makefile: use 'python3 -m pytest' instead of 'which pytest'
   Debian's python3-pytest package does not install a 'pytest' binary in
   PATH (only 'py.test-3' and 'pytest-3'); 'python3 -m pytest' is the
   reliable invocation regardless of binary name.

2. .github/workflows/run-tests.yml: gate build_images on style_checker
   so a style failure stops CI before any image builds start.

3. tests/network.py: two fixes for pyroute2 >= 0.5.17 strict UTF-8:
   - replace universal_newlines=True with encoding='utf-8',
     errors='replace' in both NSPopen calls so non-ASCII bytes from
     pg_autoctl are replaced rather than raising UnicodeDecodeError.
   - add LC_ALL=C LANG=C to subprocess env so PostgreSQL produces
     ASCII-only error messages inside network namespaces.

4. tests/tablespaces/conftest.py: add project root to sys.path so
   the tablespace tests can import as 'from tests.tablespaces.xxx'.
   nosetests did this implicitly; pytest does not.

5. tests/pgautofailover_utils.py: fix run_sql_query when autocommit=True.
   psycopg2's 'with conn:' context manager wraps an implicit BEGIN even
   when autocommit is on (behaviour varies by psycopg2 version), blocking
   DDL like CREATE TABLESPACE.  Use explicit commit/rollback/finally.
@dimitri dimitri self-assigned this Jul 9, 2026
@dimitri dimitri added Developer productivity Enhancements to ability to ship quality code Packaging and CI Enhancements to our CI integration labels Jul 9, 2026
@dimitri
dimitri merged commit e18fade into main Jul 9, 2026
28 of 29 checks passed
@dimitri
dimitri deleted the test/pytest-migration branch July 9, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Developer productivity Enhancements to ability to ship quality code Packaging and CI Enhancements to our CI integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant