Skip to content

Commit

Permalink
Trac #33521: doctesting with pytest fails on system install of sage
Browse files Browse the repository at this point in the history
pytest assumes the directory containing the code to be tested is
writable. This is not currently the case on sage-on-distro were most of
the time testing is done after installing on the system.

Here is a typical result
{{{
============================= test session starts
==============================
platform linux -- Python 3.10.2, pytest-7.0.1, pluggy-1.0.0
rootdir: /usr
plugins: hypothesis-6.38.0
collected 0 items

=============================== warnings summary
===============================
../../usr/lib/python3.10/site-packages/_pytest/cacheprovider.py:433
  /usr/lib/python3.10/site-packages/_pytest/cacheprovider.py:433:
PytestCacheWarning: could not create cache path
/usr/.pytest_cache/v/cache/nodeids
    config.cache.set("cache/nodeids", sorted(self.cached_nodeids))

../../usr/lib/python3.10/site-packages/_pytest/stepwise.py:52
  /usr/lib/python3.10/site-packages/_pytest/stepwise.py:52:
PytestCacheWarning: could not create cache path
/usr/.pytest_cache/v/cache/stepwise
    session.config.cache.set(STEPWISE_CACHE_DIR, [])

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
}}}
pytest can be started with some option to change the location of the
cache directory `-o cache_dir=...`. pytest is currently called from
`sage-runtest` and this is where we may want to apply any changes.

URL: https://trac.sagemath.org/33521
Reported by: fbissey
Ticket author(s): Matthias Koeppe
Reviewer(s): François Bissey
  • Loading branch information
Release Manager committed Apr 19, 2022
2 parents 79dc3df + 84d3d9e commit 781a14a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/bin/sage-runtests
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ if __name__ == "__main__":
DC = DocTestController(args, args.filenames)
err = DC.run()

# Trac #33521: Do not run pytest if the pytest configuration is not available.
# This happens when the source tree is not available and SAGE_SRC falls back
# to SAGE_LIB.
from sage.env import SAGE_SRC
if not all(os.path.isfile(os.path.join(SAGE_SRC, f))
for f in ["conftest.py", "tox.ini"]):
sys.exit(err)

try:
exit_code_pytest = 0
import pytest
Expand All @@ -169,7 +177,7 @@ if __name__ == "__main__":
exit_code_pytest = 0

except ModuleNotFoundError:
print("Pytest is not installed, skip checking tests that rely on it.")
print("pytest is not installed in the venv, skip checking tests that rely on it")

if err == 0:
sys.exit(exit_code_pytest)
Expand Down

0 comments on commit 781a14a

Please sign in to comment.