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

doctest does not consider usefixtures in pytest.ini #275

Closed
pytestbot opened this issue Mar 14, 2013 · 4 comments
Closed

doctest does not consider usefixtures in pytest.ini #275

pytestbot opened this issue Mar 14, 2013 · 4 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Takafumi Arakaki (BitBucket: tkf, GitHub: tkf)


Running py.test with the following files fail:

pytest.ini:

#!ini

[pytest]
addopts = --doctest-modules
usefixtures = myfixture

conftest.py:

#!python

import pytest


@pytest.fixture()
def myfixture(monkeypatch):
    monkeypatch.setenv('MYENV', 'value')

test_env.py:

#!python

"""
>>> os.environ['MYENV'] == 'value'
True
"""

import os


def test():
    assert os.environ['MYENV'] == 'value'

Normal test passes but doctest fails:

============================== test session starts ===============================
platform linux2 -- Python 2.7.2 -- pytest-2.3.4
plugins: xdist, ipdb
collected 3 items 

conftest.py .
test_env.py F.

==================================== FAILURES ====================================
___________________________________ [doctest] ____________________________________
001 """
002 >>> os.environ['MYENV'] == 'value'
UNEXPECTED EXCEPTION: KeyError('MYENV',)
Traceback (most recent call last):

  File "/usr/lib/python2.7/doctest.py", line 1254, in __run
    compileflags, 1) in test.globs

  File "<doctest test_env[0]>", line 1, in <module>

  File "/.../lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)

KeyError: 'MYENV'

/.../test_env.py:2: UnexpectedException
======================= 1 failed, 2 passed in 0.02 seconds ====================

@pytestbot
Copy link
Contributor Author

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


doctest does not support fixtures as of now

@pytestbot
Copy link
Contributor Author

Original comment by Anatoly Bubenkov (BitBucket: bubenkoff, GitHub: bubenkoff):


starting on this

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


@RonnyPfannschmidt doctest provide "getfixture" to access fixtures these days. Providing "usefixtures" makes sense, subsequently.

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


fix issue275 - allow usefixtures and autouse fixtures
for running doctest text files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant