diff --git a/.coveragerc b/.coveragerc index fbddc8087..82a5b7624 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,3 +5,4 @@ omit = tests __init__.py scip.pyx +patch = subprocess diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index d0c36a448..dd00cac94 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -44,7 +44,7 @@ jobs: uses: pypa/cibuildwheel@v2.21.1 env: CIBW_ARCHS: ${{ matrix.arch }} - CIBW_TEST_REQUIRES: pytest + CIBW_TEST_GROUPS: test CIBW_TEST_COMMAND: "pytest {project}/tests" CIBW_MANYLINUX_*_IMAGE: manylinux_2_28 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 6ffd89978..3fce442b8 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -36,7 +36,7 @@ jobs: - name: Prepare python environment run: | python -m pip install --upgrade pip - python -m pip install networkx cython pytest-cov numpy + python -m pip install --group coverage - name: Install PySCIPOpt run: | @@ -47,7 +47,8 @@ jobs: - name: Run pyscipopt tests run: | sudo apt-get install tzdata locales -y && sudo locale-gen pt_PT && sudo update-locale # add pt_PT locale that is used in tests - coverage run -m pytest + coverage run -m pytest -nauto + coverage combine coverage report -m coverage xml diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index e0f1c3424..52e4dd9a5 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -34,14 +34,14 @@ jobs: - name: Prepare python environment run: | python -m pip install --upgrade pip - python -m pip install networkx pytest-cov numpy + python -m pip install --group test-full - name: Install PySCIPOpt run: python -m pip install . - name: Run pyscipopt tests run: | - py.test + py.test -nauto Windows-test: env: @@ -70,7 +70,7 @@ jobs: shell: powershell run: | python -m pip install --upgrade pip - python -m pip install networkx pytest-cov numpy + python -m pip install --group test-full - name: Install PySCIPOpt shell: powershell @@ -81,7 +81,7 @@ jobs: - name: Run pyscipopt tests shell: powershell run: | - py.test + py.test -nauto MacOS-test: runs-on: macos-latest @@ -107,7 +107,7 @@ jobs: - name: Prepare python environment run: | python -m pip install --upgrade pip - python -m pip install networkx pytest-cov pytest numpy + python -m pip install --group test-full - name: Install PySCIPOpt run: | diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml index 3432ff1bb..13f4a5c81 100644 --- a/.github/workflows/test-release.yml +++ b/.github/workflows/test-release.yml @@ -28,7 +28,7 @@ jobs: - name: Prepare python environment run: | python -m pip install --upgrade pip - python -m pip install wheel cython networkx pytest-cov build + python -m pip install wheel cython build - name: Build package run: | diff --git a/.github/workflows/update-packages-and-documentation.yml b/.github/workflows/update-packages-and-documentation.yml index c6ab7fbc3..5c3f7eb6f 100644 --- a/.github/workflows/update-packages-and-documentation.yml +++ b/.github/workflows/update-packages-and-documentation.yml @@ -49,14 +49,14 @@ jobs: - name: Prepare python environment run: | python -m pip install --upgrade pip - python -m pip install wheel cython networkx pytest-cov + python -m pip install --group test-full - name: Install PySCIPOpt run: python -m pip install . - name: Run pyscipopt tests run: | - py.test + py.test -nauto windows-test: needs: release-integration-test @@ -86,7 +86,7 @@ jobs: shell: powershell run: | python -m pip install --upgrade pip - python -m pip install wheel cython networkx pytest-cov + python -m pip install --group test-full - name: Install PySCIPOpt shell: powershell run: | @@ -95,7 +95,7 @@ jobs: - name: Run pyscipopt tests shell: powershell run: | - py.test + py.test -nauto deploy-packages-and-generate-documentation: @@ -117,7 +117,7 @@ jobs: - name: Prepare python environment run: | python -m pip install --upgrade pip - python -m pip install wheel cython networkx pytest-cov build + python -m pip install wheel cython build - name: Build package run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index fbd0a4f44..d50a03be8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Implemented all binary operations between MatrixExpr and GenExpr - Fixed the type of @ matrix operation result from MatrixVariable to MatrixExpr. ### Changed +- Add a PEP 735 dependency group for test dependencies in `pyproject.toml` - Speed up MatrixVariable.sum(axis=None) via quicksum ### Removed diff --git a/INSTALL.md b/INSTALL.md index 1076b1635..ca8b1a66f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -116,17 +116,16 @@ Testing new installation ======================== To test your brand-new installation of PySCIPOpt you need -[pytest](https://pytest.org/) on your system. +some dependencies which can be installed via pip. The testing +dependencies are in the `test` dependency group. - pip install pytest - -Here is the complete [installation -procedure](https://docs.pytest.org/en/latest/getting-started.html). + pip install --group test Tests can be run in the `PySCIPOpt` directory with: : py.test # all the available tests py.test tests/test_name.py # a specific tests/test_name.py (Unix) + py.test -nauto # run tests in parallel using all available cores Ideally, the status of your tests must be passed or skipped. Running tests with pytest creates the `__pycache__` directory in `tests` and, diff --git a/docs/build.rst b/docs/build.rst index 0b27ef4d2..062c636cc 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -177,12 +177,13 @@ To use debug information in PySCIPOpt you need to build it with the following co Testing the Installation ========================== -To test your brand-new installation of PySCIPOpt you need `pytest `_ -on your system. To get pytest simply run the command: +To test your brand-new installation of PySCIPOpt you need to +install some dependencies via pip. The testing dependencies are in +the `test` dependency group. .. code-block:: bash - pip install pytest + pip install --group test Tests can be run in the PySCIPOpt directory with the commands: @@ -190,6 +191,7 @@ Tests can be run in the PySCIPOpt directory with the commands: pytest # Will run all the available tests pytest tests/test_name.py # Will run a specific tests/test_name.py (Unix) + pytest -nauto # Will run tests in parallel using all available cores Ideally, the status of your tests must be passed or skipped. Running tests with pytest creates the __pycache__ directory in tests and, occasionally, diff --git a/pyproject.toml b/pyproject.toml index 3782ea892..e56a4b6df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,21 @@ dynamic = ["version"] [project.urls] Homepage = "https://github.com/SCIP-Interfaces/PySCIPOpt" +[dependency-groups] +test = [ + "pytest", + "pytest-xdist", +] +test-full = [ + {"include-group" = "test" }, + "networkx", # only needed for a few tests +] +coverage = [ + { "include-group" = "test-full" }, + "coverage", + "cython", +] + [tool.pytest.ini_options] norecursedirs = ["check"] testpaths = ["tests"] diff --git a/tests/test_logical.py b/tests/test_logical.py index dbf99d3a6..7504a60ae 100644 --- a/tests/test_logical.py +++ b/tests/test_logical.py @@ -1,12 +1,7 @@ from pyscipopt import Model from pyscipopt import quicksum -try: - import pytest - itertools = pytest.importorskip("itertools") -except ImportError: - import itertools -product = itertools.product +import pytest # Testing AND/OR/XOR constraints diff --git a/tests/test_tsp.py b/tests/test_tsp.py index 127fc267c..9f7b556f4 100644 --- a/tests/test_tsp.py +++ b/tests/test_tsp.py @@ -1,8 +1,7 @@ from pyscipopt import Model, Conshdlr, quicksum, SCIP_RESULT - +import itertools import pytest -itertools = pytest.importorskip("itertools") networkx = pytest.importorskip("networkx") EPS = 1.e-6