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

Add a new doctest_namespace fixture #1428

Merged
merged 2 commits into from
Mar 3, 2016
Merged

Add a new doctest_namespace fixture #1428

merged 2 commits into from
Mar 3, 2016

Conversation

milliams
Copy link
Contributor

@milliams 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.

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation here seems to be off 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed 😄 I will fix and update.

@nicoddemus nicoddemus merged commit 6dd2ff5 into pytest-dev:features Mar 3, 2016
nicoddemus added a commit that referenced this pull request Mar 3, 2016
@nicoddemus
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants