Anyone know how nosetest's -m, -i and -e work?

假装没事ソ 提交于 2019-12-10 12:39:15

问题


I am trying to get nosetests to identify my tests but it is not running any of my tests properly.

I have the following file structure

Project
    +----Foo/
          +----__init__.py
          +----bar.py
    +----test/
          +----__init__.py
          +----unit/
                +----__init__.py
                +----bar_test.py
          +----functional/
                +----__init__.py
                +----foo_test.py

Within bar_test.py

class BarTest(unittest.TestCase):
     def bar_1_test():
         ...

Within foo_test.py

class FooFTest.py
     def foo_1_test():
         ...

Using -m, -i, -e options of nosetests

  • What is the regex I need to run only unit tests (under unit/, tests in class BarTest)
  • What is the regex I need run only functional tests (under functional/, tests in class FooFTest)

I've tried various combinations and can't seem to get nosetests to do what I want consistently


回答1:


The easiest way to run only the tests under Project/test/unit is to use --where. For example:

nosetests --where=Project/test/unit

Then use --match (-m) or --exclude (-e) to refine the list, if needed.

If you still want to use the regex selectors, you can probably do it like this (not tested):

nosetests --match='^Foo[\b_\./-])[Tt]est'

Executing this script from the Project directory would run all tests that start with "Foo" and end in "[Tt]est".

As a general rule, you probably want to use either --match or --exclude, but not both. These parameters both specify the pattern of the function names to match. You can refine either one by using --ignore-files which, naturally, allows you to ignore whole files.




回答2:


Given your directory structure, you can easily run segments of the tests using the --exclude option.

Run all tests:

nosetests Project

Run unit tests:

nosetests Project -e functional

Run functional tests:

nosetests Project -e unit

If you have more complex test execution needs, I'd recommend marking the tests and using the attrib package.



来源:https://stackoverflow.com/questions/8054512/anyone-know-how-nosetests-m-i-and-e-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!