Skip to main content

具有覆盖支持的并行单元测试运行器

项目描述

单元测试并行

PyPI - 状态 派皮 GitHub PyPI - Python 版本

unittest-parallel 是 Python 的并行单元测试运行器,具有覆盖支持。

要运行 unittest-parallel,请使用“-s”参数指定包含单元测试的目录,并使用“-t”参数指定包的顶级目录:

unittest-parallel -t . -s tests

默认情况下,unittest-parallel 在所有可用的 CPU 内核上运行单元测试。

要使用覆盖率运行单元测试,请添加“--coverage”选项(用于线路覆盖率)或“--coverage-branch”用于线路和分支覆盖率。

unittest-parallel -t . -s tests --coverage-branch

这个怎么运作

unittest-parallel 使用 Python 的内置单元测试发现来查找项目中的所有测试用例。然后它在请求大小的 Python 多处理池中运行所有测试用例。

类和模块夹具

Python 的 unittest 框架支持 类和模块装置。 使用“--class-fixtures”选项正确执行类fixtures。使用“--module-fixtures”选项正确执行模块夹具。请注意,这些选项会减少并行度。

示例输出

$ unittest-parallel -v -t src -s src/tests --coverage-branch --coverage-fail-under 100
Running 299 test suites (299 total tests) across 8 processes

test_first_list_then_dict (tests.test_encode.TestDecodeQueryString) ...
test_first_list_then_dict (tests.test_encode.TestDecodeQueryString) ... ok
test_compile_stdin (tests.test_main.TestMain) ...
test_validate_stdin (tests.test_main.TestMain) ...
test_array (tests.test_encode.TestDecodeQueryString) ...
test_array (tests.test_encode.TestDecodeQueryString) ... ok
...
test_simple (tests.test_schema.TestValidateTypeModelTypes) ... ok
test_typedef_unknown_type (tests.test_schema.TestValidateTypeModelTypes) ...
test_typedef_unknown_type (tests.test_schema.TestValidateTypeModelTypes) ... ok
test_struct_empty (tests.test_schema.TestValidateTypeModelTypes) ...
test_struct_empty (tests.test_schema.TestValidateTypeModelTypes) ... ok

----------------------------------------------------------------------
Ran 299 tests in 0.731s

OK

Name                                 Stmts   Miss Branch BrPart  Cover
----------------------------------------------------------------------
src/schema_markdown/__init__.py          5      0      0      0   100%
src/schema_markdown/__main__.py          2      0      0      0   100%
src/schema_markdown/encode.py           84      0     60      0   100%
src/schema_markdown/main.py             45      0     16      0   100%
src/schema_markdown/parser.py          327      0    186      0   100%
src/schema_markdown/schema.py          275      0    203      0   100%
src/schema_markdown/schema_util.py     150      0    106      0   100%
src/schema_markdown/type_model.py        4      0      0      0   100%
src/tests/__init__.py                    0      0      0      0   100%
src/tests/test_encode.py               154      0      0      0   100%
src/tests/test_main.py                 191      0      4      0   100%
src/tests/test_parser.py               363      0      0      0   100%
src/tests/test_schema.py               938      0      0      0   100%
----------------------------------------------------------------------
TOTAL                                 2538      0    575      0   100%

Total coverage is 100.00%

用法

usage: unittest-parallel [-h] [-v] [-q] [-f] [-b] [-k TESTNAMEPATTERNS]
                         [-s START] [-p PATTERN] [-t TOP] [-j COUNT]
                         [--class-fixtures] [--module-fixtures]
                         [--disable-process-pooling] [--coverage]
                         [--coverage-branch] [--coverage-rcfile RCFILE]
                         [--coverage-include PAT] [--coverage-omit PAT]
                         [--coverage-source SRC] [--coverage-html DIR]
                         [--coverage-xml FILE] [--coverage-fail-under MIN]

options:
  -h, --help            show this help message and exit
  -v, --verbose         Verbose output
  -q, --quiet           Quiet output
  -f, --failfast        Stop on first fail or error
  -b, --buffer          Buffer stdout and stderr during tests
  -k TESTNAMEPATTERNS   Only run tests which match the given substring
  -s START, --start-directory START
                        Directory to start discovery ('.' default)
  -p PATTERN, --pattern PATTERN
                        Pattern to match tests ('test*.py' default)
  -t TOP, --top-level-directory TOP
                        Top level directory of project (defaults to start
                        directory)

parallelization options:
  -j COUNT, --jobs COUNT
                        The number of test processes (default is 0, all cores)
  --class-fixtures      One or more TestCase class has a setUpClass method
  --module-fixtures     One or more test module has a setUpModule method
  --disable-process-pooling
                        Do not reuse processes used to run test suites

coverage options:
  --coverage            Run tests with coverage
  --coverage-branch     Run tests with branch coverage
  --coverage-rcfile RCFILE
                        Specify coverage configuration file
  --coverage-include PAT
                        Include only files matching one of these patterns.
                        Accepts shell-style (quoted) wildcards.
  --coverage-omit PAT   Omit files matching one of these patterns. Accepts
                        shell-style (quoted) wildcards.
  --coverage-source SRC
                        A list of packages or directories of code to be
                        measured
  --coverage-html DIR   Generate coverage HTML report
  --coverage-xml FILE   Generate coverage XML report
  --coverage-fail-under MIN
                        Fail if coverage percentage under min

发展

这个项目是使用python-build开发的。它是使用python-template开始的,如下所示:

template-specialize python-template/template/ unittest-parallel/ -k package unittest-parallel -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs' -k noapi 1

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

unittest-parallel-1.5.2.tar.gz (9.6 kB 查看哈希

已上传 source