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.