diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6ca92f83f..322561aa4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -30,6 +30,7 @@ jobs: build_images: name: Build test image (PG${{ matrix.PGVERSION }}) + needs: style_checker runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/Dockerfile b/Dockerfile index 1df68994d..1ea332536 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,8 +44,8 @@ RUN apt-get update \ make \ autoconf \ openssl \ - pipenv \ python3-nose \ + python3-pytest \ python3 \ python3-setuptools \ python3-psycopg2 \ @@ -74,7 +74,7 @@ RUN apt-get update \ postgresql-${PGVERSION} \ && rm -rf /var/lib/apt/lists/* -RUN pip3 install pyroute2>=0.5.17 +RUN pip3 install 'pyroute2>=0.5.17' RUN adduser --disabled-password --gecos '' docker RUN adduser docker sudo diff --git a/Makefile b/Makefile index 733e15540..73f062b48 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ include Makefile.azure # # LIST TESTS # -NOSETESTS = $(shell which nosetests3 || which nosetests) +PYTEST = python3 -m pytest # Tests for the monitor TESTS_MONITOR = test_extension_update @@ -78,17 +78,17 @@ TESTS_MULTI += test_multi_standbys # Included Makefile may define TEST_ARGUMENT (like for citus) TEST ?= ifeq ($(TEST),) - TEST_ARGUMENT = --where=tests + TEST_ARGUMENT = tests/*.py else ifeq ($(TEST),multi) - TEST_ARGUMENT = --where=tests --tests=$(TESTS_MULTI) + TEST_ARGUMENT = $(TESTS_MULTI:%=tests/%.py) else ifeq ($(TEST),single) - TEST_ARGUMENT = --where=tests --tests=$(TESTS_SINGLE) + TEST_ARGUMENT = $(TESTS_SINGLE:%=tests/%.py) else ifeq ($(TEST),monitor) - TEST_ARGUMENT = --where=tests --tests=$(TESTS_MONITOR) + TEST_ARGUMENT = $(TESTS_MONITOR:%=tests/%.py) else ifeq ($(TEST),ssl) - TEST_ARGUMENT = --where=tests --tests=$(TESTS_SSL) + TEST_ARGUMENT = $(TESTS_SSL:%=tests/%.py) else - TEST_ARGUMENT = $(TEST:%=tests/%.py) + TEST_ARGUMENT = tests/$(TEST).py endif # @@ -167,11 +167,10 @@ ifeq ($(TEST),tablespaces) $(MAKE) -C tests/tablespaces run-test else sudo -E env "PATH=${PATH}" USER=$(shell whoami) \ - $(NOSETESTS) \ - --verbose \ - --nologcapture \ - --nocapture \ - --stop \ + $(PYTEST) \ + -v \ + -s \ + -x \ ${TEST_ARGUMENT} endif diff --git a/Makefile.citus b/Makefile.citus index d15511f2c..75f621098 100644 --- a/Makefile.citus +++ b/Makefile.citus @@ -19,7 +19,7 @@ ifeq ($(TEST),citus) TESTS_CITUS += test_nonha_citus_operation TESTS_CITUS += test_citus_skip_pg_hba - TEST_ARGUMENT = --where=tests --tests=$(TESTS_CITUS) + TEST_ARGUMENT = $(TESTS_CITUS:%=tests/%.py) endif # this target is defined and used later in the main Makefile diff --git a/tests/network.py b/tests/network.py index 030d87db6..338d7297b 100644 --- a/tests/network.py +++ b/tests/network.py @@ -153,6 +153,8 @@ def run(self, command, user=os.getenv("USER")): user, "env", "PATH=" + os.getenv("PATH"), + "LC_ALL=C", + "LANG=C", ] + command return managed_nspopen( self.namespace, @@ -179,6 +181,8 @@ def run_unmanaged(self, command, user=os.getenv("USER")): user, "env", "PATH=" + os.getenv("PATH"), + "LC_ALL=C", + "LANG=C", ] + command return NSPopen( self.namespace, diff --git a/tests/pgautofailover_utils.py b/tests/pgautofailover_utils.py index 7aef6ecfe..7777e151b 100644 --- a/tests/pgautofailover_utils.py +++ b/tests/pgautofailover_utils.py @@ -271,16 +271,21 @@ def run_sql_query(self, query, autocommit, *args): conn = psycopg2.connect(self.connection_string()) conn.autocommit = autocommit - with conn: + try: with conn.cursor() as cur: cur.execute(query, args) try: result = cur.fetchall() except psycopg2.ProgrammingError: pass - # leaving contexts closes the cursor, however - # leaving contexts doesn't close the connection - conn.close() + if not autocommit: + conn.commit() + except Exception: + if not autocommit: + conn.rollback() + raise + finally: + conn.close() return result diff --git a/tests/tablespaces/conftest.py b/tests/tablespaces/conftest.py new file mode 100644 index 000000000..694e344d3 --- /dev/null +++ b/tests/tablespaces/conftest.py @@ -0,0 +1,8 @@ +import sys +import os + +# tablespace tests import as "from tests.tablespaces.xxx import ..." which +# requires the project root (parent of tests/) on sys.path. pytest does not +# add it automatically; nosetests used to, by treating tests/__init__.py as a +# package root. Add it here so both test runners work. +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(__file__))))