diff --git a/.github/workflows/test-packages-action-linux.yml b/.github/workflows/test-packages-action-linux.yml index e1e70dea274..2197a662318 100644 --- a/.github/workflows/test-packages-action-linux.yml +++ b/.github/workflows/test-packages-action-linux.yml @@ -200,7 +200,7 @@ jobs: run: | tools --timestamps --no-output-timeout-secs=1800 --timeout-secs=14400 vm test --skip-requirements-install ${{ matrix.fips && '--fips ' || '' }}\ --nox-session=${{ inputs.nox-session }}-pkgs --rerun-failures ${{ inputs.distro-slug }} -- ${{ matrix.tests-chunk }} \ - ${{ matrix.version && format('--prev-version {0}', matrix.version) || ''}} + ${{ matrix.version && format('--prev-version={0}', matrix.version) || ''}} - name: Download Test Run Artifacts id: download-artifacts-from-vm diff --git a/.github/workflows/test-packages-action-macos.yml b/.github/workflows/test-packages-action-macos.yml index b3d9a3f091a..686295cb17b 100644 --- a/.github/workflows/test-packages-action-macos.yml +++ b/.github/workflows/test-packages-action-macos.yml @@ -185,7 +185,7 @@ jobs: COVERAGE_CONTEXT: ${{ inputs.distro-slug }} run: | sudo -E nox --force-color -e ${{ inputs.nox-session }}-pkgs -- ${{ matrix.tests-chunk }} \ - ${{ matrix.version && format('--prev-version {0}', matrix.version) || ''}} + ${{ matrix.version && format('--prev-version={0}', matrix.version) || ''}} - name: Fix file ownership run: | diff --git a/.github/workflows/test-packages-action-windows.yml b/.github/workflows/test-packages-action-windows.yml index 28d5a1d57b3..b8d2f21d5bd 100644 --- a/.github/workflows/test-packages-action-windows.yml +++ b/.github/workflows/test-packages-action-windows.yml @@ -199,7 +199,7 @@ jobs: run: | tools --timestamps --no-output-timeout-secs=1800 --timeout-secs=14400 vm test --skip-requirements-install ${{ matrix.fips && '--fips ' || '' }}\ --nox-session=${{ inputs.nox-session }}-pkgs --rerun-failures ${{ inputs.distro-slug }} -- ${{ matrix.tests-chunk }} \ - ${{ matrix.version && format('--prev-version {0}', matrix.version) || ''}} + ${{ matrix.version && format('--prev-version={0}', matrix.version) || ''}} - name: Download Test Run Artifacts id: download-artifacts-from-vm diff --git a/noxfile.py b/noxfile.py index d69e6a444c0..48d40672f3e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1828,32 +1828,25 @@ def ci_test_onedir_pkgs(session): ] chunks = { - "install": [ - "tests/pytests/pkg/", - ], + "install": [], "upgrade": [ "--upgrade", "--no-uninstall", - "tests/pytests/pkg/upgrade/", ], "upgrade-classic": [ "--upgrade", "--no-uninstall", - "tests/pytests/pkg/upgrade/", ], "downgrade": [ "--downgrade", "--no-uninstall", - "tests/pytests/pkg/downgrade/", ], "downgrade-classic": [ "--downgrade", "--no-uninstall", - "tests/pytests/pkg/downgrade/", ], "download-pkgs": [ "--download-pkgs", - "tests/pytests/pkg/download/", ], } @@ -1894,6 +1887,17 @@ def ci_test_onedir_pkgs(session): ] + session.posargs ) + append_tests_path = True + test_paths = ( + "tests/pytests/pkg/", + str(REPO_ROOT / "tests" / "pytests" / "pkg"), + ) + for arg in session.posargs: + if arg.startswith(test_paths): + append_tests_path = False + break + if append_tests_path: + pytest_args.append("tests/pytests/pkg/") try: _pytest(session, coverage=False, cmd_args=pytest_args, env=env) except CommandFailed: @@ -1917,6 +1921,8 @@ def ci_test_onedir_pkgs(session): ] + session.posargs ) + if append_tests_path: + pytest_args.append("tests/pytests/pkg/") _pytest( session, coverage=False, @@ -1941,6 +1947,8 @@ def ci_test_onedir_pkgs(session): pytest_args.append("--use-prev-version") if chunk in ("upgrade-classic", "downgrade-classic"): pytest_args.append("--classic") + if append_tests_path: + pytest_args.append("tests/pytests/pkg/") try: _pytest(session, coverage=False, cmd_args=pytest_args, env=env) except CommandFailed: @@ -1963,6 +1971,8 @@ def ci_test_onedir_pkgs(session): pytest_args.append("--use-prev-version") if chunk in ("upgrade-classic", "downgrade-classic"): pytest_args.append("--classic") + if append_tests_path: + pytest_args.append("tests/pytests/pkg/") _pytest( session, coverage=False, diff --git a/tests/pytests/pkg/conftest.py b/tests/pytests/pkg/conftest.py index 699b9162189..e91d4e298dd 100644 --- a/tests/pytests/pkg/conftest.py +++ b/tests/pytests/pkg/conftest.py @@ -114,6 +114,58 @@ def pytest_addoption(parser): ) +@pytest.hookimpl(hookwrapper=True, trylast=True) +def pytest_collection_modifyitems(config, items): + """ + called after collection has been performed, may filter or re-order + the items in-place. + + :param _pytest.main.Session session: the pytest session object + :param _pytest.config.Config config: pytest config object + :param List[_pytest.nodes.Item] items: list of item objects + """ + # Let PyTest or other plugins handle the initial collection + yield + selected = [] + deselected = [] + pkg_tests_path = pathlib.Path(__file__).parent + + if config.getoption("--upgrade"): + for item in items: + if str(item.fspath).startswith(str(pkg_tests_path / "upgrade")): + selected.append(item) + else: + deselected.append(item) + elif config.getoption("--downgrade"): + for item in items: + if str(item.fspath).startswith(str(pkg_tests_path / "downgrade")): + selected.append(item) + else: + deselected.append(item) + elif config.getoption("--download-pkgs"): + for item in items: + if str(item.fspath).startswith(str(pkg_tests_path / "download")): + selected.append(item) + else: + deselected.append(item) + else: + exclude_paths = ( + str(pkg_tests_path / "upgrade"), + str(pkg_tests_path / "downgrade"), + str(pkg_tests_path / "download"), + ) + for item in items: + if str(item.fspath).startswith(exclude_paths): + deselected.append(item) + else: + selected.append(item) + + if deselected: + # Selection changed + items[:] = selected + config.hook.pytest_deselected(items=deselected) + + @pytest.hookimpl(tryfirst=True) def pytest_runtest_setup(item): """