是否有一个惯例来区分Python集成测试和单元测试?

是否有一个惯例来区分Python集成测试和单元测试?,python,unit-testing,integration-testing,Python,Unit Testing,Integration Testing,使用单元测试构造Python包的最常见方法如下: package/ __init__.py module_1.py module_2.py module_n.py test/ __init__.py test_module_1.py test_module_2.py test_module_n.py 我想区分单元测试(方法和函数)和集成测试(使用整个包,可能涉及其他资源)。也许这些测试应该在

使用单元测试构造Python包的最常见方法如下:

package/
    __init__.py
    module_1.py
    module_2.py
    module_n.py
    test/
        __init__.py
        test_module_1.py
        test_module_2.py
        test_module_n.py
我想区分单元测试(方法和函数)和集成测试(使用整个包,可能涉及其他资源)。也许这些测试应该在不同的包中,具有不同的文件名,和/或包含某些docstring注释


是否有这样做的标准约定?

在我们的项目中,每个包中都有单元测试,与您的案例相同,集成测试、系统测试作为顶层的单独包,即:

package_1/
  __init__.py
  module_1.py
  module_n.py
  test/
    __init__.py
    test_module_1.py
    test_module_n.py
package_n/
  __init__.py
  module_1.py
  module_n.py
  test/
    __init__.py
    test_module_1.py
    test_module_n.py
systemtest/
  __init__.py
  systemtest_1.py
  systemtest_n.py

即使项目中只有一个包,我也会使用这个约定。但是,我不确定这是否是一个标准惯例。

我只是为自己研究了一下,发现有帮助:


我真的希望在该包中保留一个包的集成测试。在这种情况下,我会在您的包中创建两个单独的子包(一个称为测试,一个称为系统测试),但这显然不是惯例,而是我的猜测。@JaceBrowning:这不是“集成测试”的一部分吗,可能涉及多个包?在这种情况下,这个测试的位置应该高于任何单元测试。@ChristophJüngling,在“其他资源”中,我指的是文件和网络IO之类的东西——这些东西通常应该在单元测试中模拟,但也包括在集成测试中。
project/
│
├── my_app/
│   └── __init__.py
│
└── tests/
    |
    └── unit/
    |   ├── __init__.py
    |   └── test_sum.py
    |
    └── integration/
        |
        ├── example_data/
        |   ├── test_basic.json
        |   └── test_complex.json
        |
        ├── __init__.py
        └── test_integration.py