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


Release history Release notifications

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
pytest_unittest_filter-0.1.0-py2.py3-none-any.whl (4.2 kB) Copy SHA256 hash SHA256 Wheel py2.py3
pytest-unittest-filter-0.1.0.tar.gz (3.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page