py.test import context problems (causes Django unit test failure)
Posted
by dhill
on Stack Overflow
See other posts from Stack Overflow
or by dhill
Published on 2010-05-06T17:25:49Z
Indexed on
2010/05/06
17:28 UTC
Read the original article
Hit count: 348
I made a following test:
# main.py
import imported
print imported.f.__module__
# imported.py
def f():
pass
# test_imported.py (py.test test case)
import imported
def test_imported():
result = imported.f.__module__
assert result == 'imported'
Running python main.py
, gives me imported
, but running py.test gives me error and result
value is moduletest.imported
(moduletest
is the name of the directory I keep the test in. It doesn't contain __init__.py
, moduletest
is the only directory containing *.py
files in ~/tmp
).
How can I fix result
value?
The long story:
I'm getting strange errors, while testing Django application. A call to reverse()
from (django.urlresolvers
). with function object foo
as argument in tests crashes with
NoReverseMatch: Reverse for 'site.app.views.foo'
. The same call inside application works. I checked and it is converted to 'app.views.foo'
(without site
prefix). I first suspected my customised test setup for Django, but then I made above test.
© Stack Overflow or respective owner