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

Add a new doctest_namespace fixture #1428

Merged
merged 2 commits into from Mar 3, 2016

Conversation

Projects
None yet
3 participants
@milliams
Contributor

milliams commented Mar 2, 2016

This resolves #1047 by introducing a new fixture doctest_namespace. This fixture can be used to inject names into the namespace in which your doctests run. The basic usage is described in doctest.rst but it works like:

# content of conftest.py
import numpy
@pytest.fixture(autouse=True)
def add_np(doctest_namespace):
    doctest_namespace['np'] = numpy

which can then be used in your doctests directly::

# content of numpy.py
def arange():
    """
    >>> a = np.arange(10)
    >>> len(a)
    10
    """
    pass

This is my first contribution to pytest so I welcome any feedback on style etc.

Add a new doctest_namespace fixture
This fixture can be used to inject names into the namespace in which
your doctests run.
# content of conftest.py
import numpy
@pytest.fixture(autouse=True)
def add_np(doctest_namespace):

This comment has been minimized.

@The-Compiler

The-Compiler Mar 2, 2016

Member

The indentation here seems to be off 😉

This comment has been minimized.

@milliams

milliams Mar 2, 2016

Contributor

Indeed 😄 I will fix and update.

@nicoddemus nicoddemus merged commit 6dd2ff5 into pytest-dev:features Mar 3, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

nicoddemus added a commit that referenced this pull request Mar 3, 2016

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Mar 3, 2016

Thanks a lot for the PR @milliams! Excellent work! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment