[TIP] load_tests() in package's __init__.py can't filter out specified sub-package
Ned Batchelder
ned at nedbatchelder.com
Fri Apr 3 08:45:20 PDT 2015
Yao, before we talk about this challenge, could you answer the questions
in the other thread you started? You're building a very complex
structure here, and I don't understand why. I think you are
overcomplicating your system.
--Ned.
On 4/3/15 8:37 AM, yaoyansibase wrote:
> 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
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20150403/ff5d190a/attachment-0001.htm>
More information about the testing-in-python
mailing list