nose, doctest, and module names in subpackages

  • Thread starter davidlmontgomery
  • Start date
D

davidlmontgomery

I'm trying to use both nosetests and doctest with the tests
pulled out into a separate file. My problem is that it
seems that I need to use different import statements
depending on from where I run the tests.

Here's my directory structure:
/dir
__init__.py
/sub
__init__.py
code_file.py
test_code_file.py
tests.txt

--- code_file.py: ---
def example_function():
return 0

--- test_code_file.py ---
def run_tests():
import doctest
result=doctest.testfile("tests.txt")
assert result[0] == 0

if __name__ == "__main__":
run_tests()

--- tests.txt ---
With this, nosetests works when run from /dir/sub, but
the import fails if nosetests is run from /dir.

If I change tests.txt to

--- tests.txt ---
(adding "sub.") then nosetests works from /dir, but not
from /dir/sub. And in this case "python test_code_file.py"
fails when run from /dir/sub.

In general, I would like to run doctests during development
from the directory where the code lives, leading me to
prefer "from code_file import", but I would like to run
nosetests from the top of the tree, leading me to want
"from sub.code_file import".

I played around with variations like using doctest.DocFileSuite
and nosetests' --with-doctest option, but nothing I tried
helped with the basic issue of the name of the module
varying depending on the execution directory.

It seems I'm missing something very basic here. Any tips
would be much appreciated.

(I'm running python 2.4.1 and nosetests 0.9.0)

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top