Skip to main content

A pytest plugin for filtering unittest-based test classes

Project description

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.0 (2019-01-11)

  • Added python_unittest_exclude_underscore option

0.1.0 (2018-10-27)

  • Initial release

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-unittest-filter-0.2.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

pytest_unittest_filter-0.2.0-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest-unittest-filter-0.2.0.tar.gz.

File metadata

  • Download URL: pytest-unittest-filter-0.2.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pytest-unittest-filter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 46ceb961fd4628ac91cb9ef0728f8d5b58e45a3b398f48c8cb471fa3bc304093
MD5 6bd6915d2386e39534356ae863944539
BLAKE2b-256 b102d29bc6ccd5194bb5df272b5889c775b17c740da3a36fe5566cb51d85fdd7

See more details on using hashes here.

File details

Details for the file pytest_unittest_filter-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_unittest_filter-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for pytest_unittest_filter-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5af0510ac72a64111133917e0c5aacca9f02d77195aec067d94bbe12bb519ee9
MD5 997dd60c4d225e7853890129b83e4ed5
BLAKE2b-256 09c3b4eab4dcc0ae32cda0b070a03117c00d7f084e191061715bc63587e93ae6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page