diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 674bc52c7b..7be59df4af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -176,7 +176,7 @@ jobs: if [[ $FAST_COMPILE == "1" ]]; then export PYTENSOR_FLAGS=$PYTENSOR_FLAGS,mode=FAST_COMPILE; fi if [[ $FLOAT32 == "1" ]]; then export PYTENSOR_FLAGS=$PYTENSOR_FLAGS,floatX=float32; fi export PYTENSOR_FLAGS=$PYTENSOR_FLAGS,warn__ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc__cxxflags=-pipe - python -m pytest -r A --verbose --runslow --durations=50 --cov=pytensor/ --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail $PART --benchmark-skip + pytest --import-mode=importlib -r A --verbose --runslow --durations=50 --cov=pytensor/ --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail $PART --benchmark-skip env: MATRIX_ID: ${{ steps.matrix-id.outputs.id }} MKL_THREADING_LAYER: GNU @@ -231,7 +231,7 @@ jobs: shell: micromamba-shell {0} run: | export PYTENSOR_FLAGS=mode=FAST_COMPILE,warn__ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc__cxxflags=-pipe - python -m pytest --runslow --benchmark-only --benchmark-json output.json + pytest --import-mode=importlib --runslow --benchmark-only --benchmark-json output.json - name: Store benchmark result uses: benchmark-action/github-action-benchmark@v1 with: diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000000..a053bba704 --- /dev/null +++ b/__init__.py @@ -0,0 +1,11 @@ +from pathlib import Path + + +repo_root = Path(__file__).parent + +raise RuntimeError( + f"Python is looking for PyTensor in {repo_root}, but it's " + f"actually located in {repo_root / 'pytensor'}. Probably " + f"you need to change your working directory from {Path.cwd()} " + f"to {repo_root}." +) diff --git a/conftest.py b/conftest.py index 873da8446a..c99b54815f 100644 --- a/conftest.py +++ b/conftest.py @@ -1,8 +1,14 @@ import os +import sys +from pathlib import Path import pytest +repo_root = Path(__file__).parent +sys.path.insert(0, str(repo_root)) + + def pytest_sessionstart(session): os.environ["PYTENSOR_FLAGS"] = ",".join( [ diff --git a/pyproject.toml b/pyproject.toml index 81a1285da8..63cccda6d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -117,7 +117,12 @@ versionfile_build = "pytensor/_version.py" tag_prefix = "rel-" [tool.pytest] -addopts = "--durations=50 --doctest-modules pytensor --ignore=pytensor/misc/check_duplicate_key.py --ignore=pytensor/link" +addopts = [ + "--durations=50", + "--doctest-modules=pytensor", + "--ignore=pytensor/misc/check_duplicate_key.py", + "--ignore=pytensor/link" +] testpaths = "tests/" [tool.ruff] @@ -163,6 +168,7 @@ warn_return_any = true warn_unreachable = true files = ["pytensor", "tests"] plugins = ["numpy.typing.mypy_plugin"] +explicit_package_bases = true [tool.cibuildwheel] build = "*"