From bc349a5f9115561f512de2b510e74efb3968c330 Mon Sep 17 00:00:00 2001 From: ElliottKasoar <45317199+ElliottKasoar@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:40:17 +0000 Subject: [PATCH] Fix pytest and tox (#98) * Fix pytest and tox * Remove explicitly exporting JANUS_PATH in CI --------- Co-authored-by: ElliottKasoar --- .github/workflows/ci.yml | 2 -- pyproject.toml | 1 + tests/conftest.py | 3 ++- tox.ini | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fc35a9e..d1221c34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,14 +46,12 @@ jobs: run: | poetry env use ${{ matrix.python-version }} poetry install --with dev - echo "JANUS_PATH=$(poetry run which janus)" >> $GITHUB_ENV - name: Run test suite env: # show timings of test PYTEST_ADDOPTS: "--durations=0" - JANUS_PATH: ${{ env.JANUS_PATH }} run: poetry run pytest --cov aiida_mlip --cov-append . - name: Report coverage to Coveralls diff --git a/pyproject.toml b/pyproject.toml index 2f18c332..513cb1c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -97,6 +97,7 @@ filterwarnings = [ "ignore::DeprecationWarning:plumpy:", "ignore::DeprecationWarning:yaml:", ] +pythonpath = ["."] [tool.coverage.run] # Configuration of [coverage.py](https://coverage.readthedocs.io) diff --git a/tests/conftest.py b/tests/conftest.py index 1f324544..2285c7da 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ import os from pathlib import Path +import shutil import pytest @@ -93,7 +94,7 @@ def janus_code(aiida_local_code_factory): `Code` The janus code instance. """ - janus_path = os.environ.get("JANUS_PATH") + janus_path = shutil.which("janus") or os.environ.get("JANUS_PATH") return aiida_local_code_factory(executable=janus_path, entry_point="janus.sp") diff --git a/tox.ini b/tox.ini index 42629170..bd9a25b8 100644 --- a/tox.ini +++ b/tox.ini @@ -6,10 +6,9 @@ usedevelop=True [testenv:py{39,310,311,312}] description = Run the test suite against Python versions -allowlist_externals = poetry, sh +allowlist_externals = poetry commands_pre = poetry install --no-root --sync -# Export path to janus executable installed in tox environment before running pytest -commands = sh -c 'export JANUS_PATH=$(which janus); exec "$@"' _ poetry run pytest --cov aiida_mlip --import-mode importlib +commands = poetry run pytest {posargs} --cov aiida_mlip --import-mode importlib [testenv:pre-commit] description = Run the pre-commit checks