Skip to content

fix:imports placing fixed #40406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import doctest
import inspect
import sys
import traceback
import warnings
from pathlib import Path
from typing import Any, Iterable, Optional
Expand All @@ -26,11 +27,12 @@
)
from _pytest.pathlib import ImportMode, import_path

from sage.doctest.forker import (
init_sage,
showwarning_with_traceback,
)
import sage.repl.ipython_kernel.all_jupyter_kernel
from sage.doctest.forker import init_sage, showwarning_with_traceback
from sage.doctest.parsing import SageDocTestParser, SageOutputChecker
from sage.features import FeatureNotPresentError
from sage.repl.rich_output import get_display_manager
from sage.repl.user_globals import set_globals


class SageDoctestModule(DoctestModule):
Expand All @@ -42,7 +44,6 @@ class SageDoctestModule(DoctestModule):
"""

def collect(self) -> Iterable[DoctestItem]:
import doctest

class MockAwareDocTestFinder(doctest.DocTestFinder):
"""A hackish doctest finder that overrides stdlib internals to fix a stdlib bug.
Expand Down Expand Up @@ -72,9 +73,9 @@ def _find_lineno(self, obj, source_lines):
source_lines,
)

def _find(
def find( # type: ignore[override]
self, tests, obj, name, module, source_lines, globs, seen
) -> None:
):
if _is_mocked(obj):
return
with _patch_unwrap_mock_aware():
Expand Down Expand Up @@ -117,8 +118,6 @@ def _find(
# Uses internal doctest module parsing mechanism.
finder = MockAwareDocTestFinder()
optionflags = get_optionflags(self.config)
from sage.features import FeatureNotPresentError

runner = _get_runner(
verbose=False,
optionflags=optionflags,
Expand Down Expand Up @@ -273,7 +272,6 @@ def pytest_addoption(parser):

# Monkey patch exception printing to replace the full qualified name of the exception by its short name
# TODO: Remove this hack once migration to pytest is complete
import traceback

old_format_exception_only = traceback.format_exception_only

Expand Down Expand Up @@ -308,8 +306,6 @@ def doctest_run(
out: Any = None,
clear_globs: bool = True,
) -> doctest.TestResults:
from sage.repl.rich_output import get_display_manager
from sage.repl.user_globals import set_globals

traceback.format_exception_only = format_exception_only

Expand All @@ -333,9 +329,8 @@ def add_imports(doctest_namespace: dict[str, Any]):
See `pytest documentation <https://docs.pytest.org/en/stable/doctest.html#doctest-namespace-fixture>`.
"""
# Inject sage.all into each doctest
import sage.repl.ipython_kernel.all_jupyter

dict_all = sage.repl.ipython_kernel.all_jupyter.__dict__
dict_all = sage.repl.ipython_kernel.all_jupyter_kernel.__dict__

# Remove '__package__' item from the globals since it is not
# always in the globals in an actual Sage session.
Expand Down