[TIP] load_tests() in package's __init__.py can't filter out specified sub-package

yaoyansibase yaoyansibase at aliyun.com
Fri Apr 3 05:37:15 PDT 2015


Hi all,
I use python 2.7.3 on windows7 x64. And here is my package structure:

project_0001/
  |___plugin_0001/
  |    |___test/
  |    |     |___test_0001/
  |    |     |     |___ __init__.py
  |    |     |     |___ test.py
  |    |     |
  |    |     |___test_0002/
  |    |     |     |___ __init__.py
  |    |     |     |___ test.py
  |    |     |
  |    |     |___test_0003/
  |    |     |     |___ __init__.py
  |    |     |     |___ test.py
  |    |     |
  |    |     |___ __init__.py
  |    |     |___ test.py
  |    |
  |    |_____ __init__.py
  |    |_____ test.py

I can run all these test cases by typing the following command:
cd \project_0001\plugin_0001\test
python -m unittest discover

Now I'm going to filter out packages test_0002 and test_0003. So I add load_tests(...) in project_0001\plugin_0001\test\__init__.py, like this:
def load_tests(loader, standard_tests, pattern):
    # top level directory cached on loader instance
    this_dir = os.path.dirname(__file__)
    package_tests = loader.discover(start_dir=this_dir, pattern='test_0001')
    standard_tests.addTests(package_tests)
    return standard_tests

and run the following command:
cd \project_0001\plugin_0001\test
python -m unittest discover
But test_0002 and test_0003 are not filtered out all.

Then I copy project_0001\plugin_0001\test\__init__.py to project_0001\plugin_0001\__init__.py, and run the following command:
cd \project_0001\plugin_0001\
python -m unittest discover
But test_0002 and test_0003 are not filtered out all too.


Is there anything wrong in my steps? how to filter out packages test_0002 and test_0003?

Cheers
yao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20150403/593e09e4/attachment.htm>


More information about the testing-in-python mailing list