3

I have my code organized like this:

base_project_dir/src /tests /test1.py /test2.py

in test1.py and test2.py I have the classes extending unittest.TestCase

according to python API doc, I should be able to run

python -m unittest tests from base dir and run all tests. but doing so shows that it finds 0 tests. so I added from test1 import * from test2 import *

into tests/__init__.py

now the above command works. but when I want to run individual tests, it sources the module init, which forcefully run all tests.

what is the correct way to organize this?

thanks Yang

4

1 回答 1

1

在你的主项目目录中试试这个:

python -m unittest discover -v

这样您就不会更改相对导入的位置。当您这样做时python -m unittest tests,它首先切换到此目录,然后无法再导入项目代码。

于 2012-10-01T22:57:05.870 回答