Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Only run doctests in pytest when doctest-modules is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed May 6, 2022
1 parent 3ee9815 commit f863428
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,10 @@ if [ "$1" = '-pytest' -o "$1" = '--pytest' ]; then
for a in $*; do
case $a in
-*) ;;
*) exec pytest --rootdir="$SAGE_SRC" "$@"
*) exec pytest --rootdir="$SAGE_SRC" --doctest-modules "$@"
esac
done
exec pytest --rootdir="$SAGE_SRC" "$@" "$SAGE_SRC"
exec pytest --rootdir="$SAGE_SRC" --doctest-modules "$@" "$SAGE_SRC"
else
echo "Run 'sage -i pytest' to install"
fi
Expand Down
11 changes: 6 additions & 5 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def pytest_collect_file(
# hit this here if someone explicitly runs `pytest some_file.pyx`.
return pytest.skip("Skipping Cython file")
elif file_path.suffix == ".py":
return SageDoctestModule.from_parent(parent, path=file_path)
if parent.config.option.doctestmodules:
return SageDoctestModule.from_parent(parent, path=file_path)


@pytest.fixture(autouse=True)
Expand All @@ -142,12 +143,12 @@ def add_imports(doctest_namespace: dict[str, Any]):
"""
# Inject sage.all into each doctest
dict_all = sage.all.__dict__

# Remove '__package__' item from the globals since it is not
# always in the globals in an actual Sage session.
dict_all.pop('__package__', None)
dict_all.pop("__package__", None)

sage_namespace = dict(dict_all)
sage_namespace['__name__'] = '__main__'
sage_namespace["__name__"] = "__main__"

doctest_namespace.update(**sage_namespace)

0 comments on commit f863428

Please sign in to comment.