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.

This plugin provides a new config option python_unittest_classes that 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 exclude classes those names start with underscore:
[pytest]
python_unittest_classes = [!_]*
  • to include only classes those names start with Test or Check:
[pytest]
python_unittest_classes = Test* Check*

or alternatively:

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

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.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_unittest_filter-0.1.0-py2.py3-none-any.whl (4.2 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: pytest-unittest-filter-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 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.1.0.tar.gz
Algorithm Hash digest
SHA256 f95518dcf2170abfabe5205cc0392d2dc80d88793321c53fcac952682b0dbf3b
MD5 31f8564baa5d4bc62d6c368285b0fcc3
BLAKE2b-256 d17d4d8e029afdb6de7ed7db9d598207b4105bd596395d4140be9212a9841748

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_unittest_filter-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.2 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.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7d7ecdad313c30cbe92ffcb2b927b276edf9a758c0fb94dfc64d4404aff2a88c
MD5 7e1d43aa65ff8b0b2757b00cbbe1cfec
BLAKE2b-256 cbf9f8937ebad109789b9d820203045898573e45a322bb05b9a7995c57bddac6

See more details on using hashes here.

Supported by

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