Python unittest and discovery

后端 未结 3 1469
你的背包
你的背包 2021-02-01 14:01

I have directories, which contain files named like: test_foo.py

Each file is a test case.

I would like to

  1. Run all the tests in a direc

3条回答
  •  情书的邮戳
    2021-02-01 14:39

    I ran into the same issue when running python -m unittest discover. Here is a good checklist to verify your setup. Nose is more flexible with the allowed configurations, but not necessarily better.

    1. Make sure all files/directories start with test. Do not use test-something.py, since that is not a valid Python module name. Use test_something.py.

    2. If you are putting your tests in a sub-directory (e.g. test/), make sure you create a test/__init__.py file so python will treat the directory as a package.

    3. All class test cases definitions must be extend unittest.TestCase. For example,

      class DataFormatTests(unittest.TestCase)
      

提交回复
热议问题