Skip to main content

pytest plugin to select tests based on attributes similar to the nose-attrib plugin

Project description

https://travis-ci.org/AbdealiJK/pytest-attrib.svg?branch=master

pytest-attrib

The pytest-attrib plugin extends py.test with the ability to select tests based on a criteria rather than just the filename or pytest.marks. For example, you might want to run only tests that need internet connectivity, or tests that are slow.

The pytest.mark plugin already provides a featrure to mark tests and run only the marked tests. This plugin also allows to run expressions on the attributes of the class, and does not require the pytest.mark decorator.

It offers features similar to the nose plugin nose-attrib.

Installation

Install the plugin with:

pip install pytest-attrib

Usage examples

To use the plugin, the -a CLI argument has been provided. Consider a project with the test file:

import unittest

class MyTestCase(unittest.TestCase):
    def test_function(self):
        assert 1 == 1

class MySlowTestCase(unittest.TestCase):
    slow = True

    def test_slow_function(self):
        import time
        time.sleep(5)
        assert 1 == 1

Using pytest-attrib, only the slow tests can be run using:

$ py.test -a slow

Or run only the fast tests using:

$ py.test -a "not slow"

The expression given in the -a argument can be even more complex, for example:

$ py.test -a "slow and requires_internet"
$ py.test -a "slow and not requires_internet"

It can also do conditional arguments like:

$ py.test -a "speed=='slow' and requires_internet"

LICENSE

https://img.shields.io/github/license/AbdealiJK/pytest-attrib.svg

This code falls under the MIT License. Please note that some files or content may be copied from other places and have their own licenses. Dependencies that are being used to generate the databases also have their own licenses.

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-attrib-0.1.2.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file pytest-attrib-0.1.2.tar.gz.

File metadata

File hashes

Hashes for pytest-attrib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 124ee7aef7cd19a27b6a7d0f2bc41749ed51566b46c88f484b320ce26a09469a
MD5 a6491e71dc7a1fcffbd3251fdbd21d6c
BLAKE2b-256 18598fbfd0abfca324334637e6905775bd6ea7fb50192b1b0f72c532f4aa00fc

See more details on using hashes here.

Supported by

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