Skip to main content

pytest-unittest-filter

Build Status PyPI

A pytest plugin for filtering unittest-based test classes

Description

pytest has unittest-based tests support out of the box. It eases incremental transition from legacy test suite to pytest for existing projects, but it has one drawback: there is no way to exclude some test cases (unittest.TestCase subclasses) from collection. pytest has python_classes config option, but, as noted in documentation, this option doesn't affect unittest.TestCase subclasses:

Note that unittest.TestCase derived classes are always collected regardless of this option, as unittest‘s own collection framework is used to collect those tests.

It's probably OK for projects that uses builtin unittest test runner (python -m unittest) because the latter has no any include/exclude option either, but it can be inconvenient if a project test suite is used with nose test runner and relies on hard-coded leading underscore filter.

The plugin provides two new config options: python_unittest_classes and python_unittest_exclude_underscore.

python_unittest_classes

This option works like the python_classes option mentioned above but for unittest.TestCase subclasses:

One or more name prefixes or glob-style patterns determining which classes are considered for test collection. Search for multiple glob patterns by adding a space between patterns.

A default value is none (no value), i.e. all unittest.TestCase subclasses are collected by default.

Examples

  • to include only classes with names starting with Test or Check:

    [pytest]
    python_unittest_classes = Test* Check*
    

    or alternatively:

    [pytest]
    python_unittest_classes = Test Check
    
  • to include only classes with names ending with TestCase:

    [pytest]
    python_unittest_classes = *TestCase
    
  • to exclude classes with names starting with underscore:

    [pytest]
    python_unittest_classes = [!_]*
    

python_unittest_exclude_underscore

This boolean option can be used to mimic hard-coded nose selector behaviour. If the option set to true, all classes with names that start with _ will be excluded. Thus, the last example above can be rewritten as following:

[pytest]
python_unittest_exclude_underscore = true

A default value is false.

Both options can be combined. The following two examples are equivalent:

[pytest]
python_unittest_classes = [!_]*Test [!_]*Check
[pytest]
python_unittest_classes = *Test *Check
python_unittest_exclude_underscore = true

Changelog

0.2.1 (2019-01-12)

  • Fixed bug where python_unittest_exclude_underscore was applied to any collected item, not only unittest classes

0.2.0 (2019-01-11)

  • Added python_unittest_exclude_underscore option

0.1.0 (2018-10-27)

  • Initial release

License

MIT License

Release files for pytest-unittest-filter 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-unittest-filter 0.2.1
File Size Uploaded
pytest-unittest-filter-0.2.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-unittest-filter 0.2.1
File Interpreter ABI Platform
pytest_unittest_filter-0.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 8.8 kB

Release files / pytest-unittest-filter-0.2.1.tar.gz

Download URL pytest-unittest-filter-0.2.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
92dc98bb5e3965e90246d93ce6f23bbc83fa0d8fa3610245b47400f48ac5045b
BLAKE2b-256 checksum
How to use checksums
fb35b047e86881e80273291f287e8d9c9ad41f522dfce3e3ca502a89740f5f6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release files / pytest_unittest_filter-0.2.1-py2.py3-none-any.whl

Download URL pytest_unittest_filter-0.2.1-py2.py3-none-any.whl
Size 4.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
09f8ac3c93ea7dfcb3215ea0c2cb5a42dbe545bacabf00bf2390580c68ea1714
BLAKE2b-256 checksum
How to use checksums
e0e0f94d49b0c7f75f2f794798e1621684728e16c75501ad028681419c2731ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page