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

adjusting globals before doctests #1047

Closed
mattip opened this issue Sep 22, 2015 · 6 comments
Closed

adjusting globals before doctests #1047

mattip opened this issue Sep 22, 2015 · 6 comments
Labels
plugin: doctests related to the doctests builtin plugin status: help wanted developers would like help from experts on this topic type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@mattip
Copy link

mattip commented Sep 22, 2015

numpy doctests sometimes use np i.e. they assume import numpy as np was run before the tests How can this be done in pytest?

@RonnyPfannschmidt
Copy link
Member

currently there is no builtin support, the "easy" way is to just copy the plugin

i propose adding a doctestrunner fxture thats module scoped and can be modified by autouse fixtures

@RonnyPfannschmidt
Copy link
Member

@mattip any more info ?

@mattip
Copy link
Author

mattip commented Oct 10, 2015

No. I am not a pytest power user, I don't know how to "copy the plugin" (what plugin, where to copy it to?) nor do I know how to even begin to approach the second thing you said.

@RonnyPfannschmidt
Copy link
Member

@mattip i see,

my proposal would be to introduce a pytest_doctest_namespace fixture,

then you would be able to do the following in a conftest.py

import pytest
import numpy

@pytest.fixture(autouse=True)
def add_numpy(pytest_doctest_namespace):
  """autouse fixture to automatically add numpy access to doctest tests"""
  doctest_namespace['np'] = numpy

@nicoddemus any comments on that idea

@nicoddemus
Copy link
Member

Looks good to me! 👍

@RonnyPfannschmidt RonnyPfannschmidt added type: enhancement new feature or API change, should be merged into features branch status: help wanted developers would like help from experts on this topic type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature plugin: doctests related to the doctests builtin plugin labels Nov 18, 2015
@nicoddemus
Copy link
Member

Merged in #1428, thanks to @milliams!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: doctests related to the doctests builtin plugin status: help wanted developers would like help from experts on this topic type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

3 participants