Skip to content
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

Run doctests without implicit imports under pytest/doctestplus #15819

Open
oscarbenjamin opened this issue Jan 21, 2019 · 0 comments
Open

Run doctests without implicit imports under pytest/doctestplus #15819

oscarbenjamin opened this issue Jan 21, 2019 · 0 comments
Labels
Testing Related to the test runner. Do not use for test failures unless it relates to the test runner itself

Comments

@oscarbenjamin
Copy link
Contributor

@drdavella @asmeurer

Recently merged #15768 makes it possible to run doctests under pytest using the pytest-doctestplus plugin from astropy. Sympy's existing (internal) doctest runner runs doctests differently from the stdlib doctest module, the pytest default doctest plugin, and the doctestplus plugin.

Specifically the difference is that Sympy's doctest runner requires all names to be explicitly imported. The other doctest runners (following the stdlib) all provide implicit imports from the defining module so e.g. you can do

# mod.py

def func():
    '''
    >>> func()
    1
    '''
    return 1

and the test will pass. Sympy's test runner would treat the other as an error and require instead:

# mod.py

def func():
    '''
    >>> from mod import func
    >>> func()
    1
    '''
    return 1

It is not currently possible to have this behaviour with doctestplus but I don't think it would be hard to add support for it. I think it just amounts to setting globs to an empty dict here:
https://github.com/astropy/pytest-doctestplus/blob/master/pytest_doctestplus/plugin.py#L376
There would need to be some setting in doctestplus to control this though.

@oscarbenjamin oscarbenjamin added the Testing Related to the test runner. Do not use for test failures unless it relates to the test runner itself label Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing Related to the test runner. Do not use for test failures unless it relates to the test runner itself
Projects
None yet
Development

No branches or pull requests

1 participant