tests: migrate from nosetests to pytest - #1134
Merged
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Switch the Python test runner from nosetests to pytest. nosetests crashes on Python 3.11+ because
collections.Callablewas removed in Python 3.10 and nose'ssuite.pystill references it. pytest is the modern replacement and is available in Bullseye apt aspython3-pytest.Changes
Dockerfilepipenv(unused) withpython3-pytestin the apt install block'pyroute2>=0.5.17'so the shell does not strip the>=operatorMakefile/Makefile.citusNOSETESTS→PYTEST = python3 -m pytest(reliable regardless of binary name; Debian'spython3-pytestinstallspy.test-3, notpytest)TEST_ARGUMENTformat: nosetests--where=tests --tests=foo,bar→ pytest path styletests/foo.py tests/bar.pytests/*.pyglob (nottests/) to avoid descending intotests/tablespaces/which has its own make target and import layout-v -s -xreplace--verbose --nologcapture --nocapture --stoptests/network.pyuniversal_newlines=Truewithencoding='utf-8', errors='replace'in bothNSPopencalls so non-ASCII bytes from pg_autoctl output are replaced rather than raisingUnicodeDecodeErrorLC_ALL=CLANG=Cto 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)sys.pathso tablespace tests can import asfrom tests.tablespaces.xxx import …; nosetests satisfied this implicitly, pytest does nottests/pgautofailover_utils.pyrun_sql_querywhenautocommit=True: psycopg2'swith conn:context manager wraps an implicitBEGINeven when autocommit is on, blocking DDL likeCREATE TABLESPACE; use explicit commit/rollback/finally instead.github/workflows/run-tests.ymlneeds: style_checkertobuild_imagesso a style failure stops CI before any image builds startTesting
Validated locally:
TEST=single make run-testwith PG17 — 88 passed, 0 failed (8 min).