Skip to main content

Management of Pytest dependencies via regex patterns

Project description

pytest-regex-dependency

Management of Pytest dependencies via regex patterns

Installation

pip install pytest-regex-dependency

Use

The following examples are possible use cases for this plugin

  • Test depends on tests with node Ids matching a specified pattern:

    test_foo.py

    import pytest
            
    
    def test_a():
        pass
    
    @pytest.mark.regex_dependency('test_foo\.py::test_a')
    def test_b():
        pass
    
  • Test depends on all tests within module:

    test_dependency.py

    def test_a():
        pass
    
    def test_b():
        pass
    

    test_bar.py

    import pytest
            
    @pytest.mark.regex_dependency('test_dependency\.py', target='module')
    def test_a():
        pass
    
  • Test depends on all tests within class:

    import pytest
            
    
    class TestClass:
        def test_a(self):
            pass
    
    @pytest.mark.regex_dependency('TestClass', target="class")
    def test_b():
        pass
    
  • Test depends on all tests functions matching a specified pattern:

    import pytest
            
    
    def test_1():
        pass
    
    def test_2():
        pass
    
    def test_3():
        pass
    
    @pytest.mark.regex_dependency('test_[0-9]+$', target='function')
    def test_a():
        pass
    

Considerations

  • If a test's pattern is not met, the test function will run

    In the following example test_b will run:

    import pytest
            
    
    def test_a():
        pass
    
    @pytest.mark.regex_dependency('test_1')
    def test_b():
        pass
    
  • The outcome of all phases of a dependency test is consider when determining if the calling test should be skipped. This includes the dependency test's setup, call, and teardown phases. If any of the phases do not match the calling test's allowed_outcomes requirement, the test will be skipped. This comes into light when a dependency test's fixture teardown logic fails but the dependency test succeeds.

    The following is an example of this scenario:

    import pytest
            
    
    @pytest.fixture
    def foo():
        yield None
        pytest.fail()
    
    def test_a(foo):
        pass
    
    @pytest.mark.regex_dependency('test_a', target="function", allowed_outcomes=["passed"])
    def test_b():
        pass
    

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-regex-dependency-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

pytest_regex_dependency-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest-regex-dependency-0.1.0.tar.gz.

File metadata

File hashes

Hashes for pytest-regex-dependency-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e59f525ab6b4b357b8edb27377433aa654fd9531b44ec103b03a7974286d710e
MD5 f74f50bee38192421c1a823691105f78
BLAKE2b-256 7d78fc9441e0acf2b75fd66ced17e251c46d15bcb04dc3857d2c1a13f2a1d293

See more details on using hashes here.

File details

Details for the file pytest_regex_dependency-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_regex_dependency-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a44973038ab56f59bb2b4db46b395472967990123dcc24e38fc973597a4eb767
MD5 7b27d3814a375f9fe34c2374c8b9b4cb
BLAKE2b-256 953fa9465a0216a1d8cd7f596a45f6b25cbe36df9175ce4c528352d711a9d60a

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