Skip to main content

A plugin that transforms the pytest output into a result similar to the RSpec. It enables the use of docstrings to display results and also enables the use of the prefixes "describe", "with" and "it".

Project description

The pytest-pyspec plugin provides semantics to the pytest output. It transforms the pytest's output into a result similar to the RSpec.

The default pytest output is like the following:

test/test_pytest.py::TestFunction::test_use_test_name PASSED
test/test_pytest.py::TestFunction::test_use_the_prefix_test PASSED
test/test_pytest.py::TestFunction::test_use_the_prefix_it PASSED
test/test_pytest.py::TestFunction::WithDocstring::test_use_docstring PASSED

The pytest-pyspec transforms the output into the following:

A function
  ✓ use test name
  ✓ use the prefix test
  ✓ use the prefix it

A function
  with docstring
    ✓ use docstring

You just need to prefix your test case classes with:

  • describe / test to represent objects
  • with / without to represent context

And prefix your tests with:

  • it / test to represent objects

The following is a sample test that generates the previous tests` output.

class TestFunction:
    def test_use_test_name(self):
        assert 1 == 1
    
    def test_use_the_prefix_test(self):
        assert 1 == 1
    
    def test_use_the_prefix_it(self):
        assert 1 == 1

    class WithDocstring:
        def test_use_docstring(self):
            assert 1 == 1

Moreover, you can use a docstring to overwrite the test description. The following tests have the same output as the previous tests:

class TestA:
    """ Function """
    def test_1(self):
        """ use test name """
        assert 1 == 1
    
    def test_2(self):
        """ use the prefix test """
        assert 1 == 1
    
    def test_3(self):
        """ use the prefix it """
        assert 1 == 1

    class TestB:
        """ with docstring """
        def test_4(self):
            """ use docstring """
            assert 1 == 1

The following test sample:

import pytest

class DescribeHouse:
    def it_has_door(self):
        assert 1 == 1
        
    class WithTwoFloors:
        def it_has_stairs(self):
            assert 1 == 1

        def it_has_second_floor(self):
            assert 1 == 1

        def it_has_third_floor(self):
            assert 1 == 2

Generates the following output:

test/test_sample.py 

A house
  ✓ has door

A house
  with two floors
    ✓ has stairs
    ✓ has second floor
    ✗ has third floor

Installing and running pySpec

pip install pytest pytest-pyspec
pytest --pyspec

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_pyspec-0.10.2.tar.gz (7.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_pyspec-0.10.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_pyspec-0.10.2.tar.gz.

File metadata

  • Download URL: pytest_pyspec-0.10.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for pytest_pyspec-0.10.2.tar.gz
Algorithm Hash digest
SHA256 b8c8cbfadecfda0ab10675d239d84efa450d283c629a90d62f8d5ef3e643138b
MD5 48de53add892ea5ccbfe01240c1e8d3b
BLAKE2b-256 5e9c6e3411eb621fb436b0fb86abec788586e2227cc7735db30b5b2fe9b29793

See more details on using hashes here.

File details

Details for the file pytest_pyspec-0.10.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_pyspec-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0ecb8ac1e2e923f30de252aaec0763283c450e706d6371a65c09ad72e790418
MD5 71edf975cdadfe4815cdbdb31b0575a3
BLAKE2b-256 aeebce904ed428483fe28e6b2cf70b6207d71d7d0105786c5b18c8a7609a5542

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