Package: pytest-honors
Report on tests that honor constraints, and guard against regressionsIntropytest-honors is apytestplugin for automatically generating reports showing which of your project’s unit tests “honor” (or “prove” or “demonstrate” or “support”) various constraints that you care about. It can also be integrated with your build pipeline to make sure that you never accidentally remove the tests that are most important to you.Below is a summary of features. More information is available at thepytest-honors documentationpage.FeaturesLightning fast! Since it piggybacks onto pytest’s own test discovery and reporting system, it adds almost no measurable overhead to your testing process.Generate nicely human-readable Markdown reports, suitable for handing to an auditor.Automatically ensure that your test coverage only ever increases with time. Fixed things stay fixed!Comes with ISO 27001 control definitions (but it’s super easy to add your own).Requirementspytest 3.5.0 or newer.InstallationYou can install “pytest-honors” viapipfromPyPI:$ pip install pytest-honorsUsageYou’ve written several thousand unit tests, but you don’t know which are actuallyimportantto you. Your team could laboriously struggle to keep docs up to date, but realistically that almost never works out as hoped. Even if your documentation is perfect, developers in the middle of a large refactoring project don’t want to flip between static text and their code.pytest-honors wants to help you. For example, given this code:import pytest
from pytest_honors.constraints import ConstraintsGroup

class MyControls(ConstraintsGroup):
    PasswordsMustBeGood = "We don't want bad passwords"
    EmailAddressesMustBeUnique = "No two users may have the same email"

@pytest.mark.honors(MyControls.PasswordsMustBeGood)
def test_password_strength():
    with pytest.raises(ValueError):
        check_password("12345")

@pytest.mark.honors(MyControls.EmailAddressesMustBeUnique)
def test_unique_email():
    add_account("User One", "spam@example.com")
    with pytest.raises(ValueError):
        add_account("User Two", "spam@example.com")In the language of pytest-honors, we say thattest_password_string“honors” the PasswordsMustBeGood constraint and thattest_unique_emailhonors the EmailAddressesMustBeUnique constraint. This is valuable on its own as developers can tell at a glance that each test actually matters to the overall design of the system, and they’re not just there because a new boss wants everyone to reach 100% test coverage. By moving important documentation to a machine-readable format that lives next to the code, we can put that information to work to give you some very useful tools.When run likepytest--honors-report-markdownreport.md, we can get nice, human-readable documentation like:# MyControls - An enumeration.

## EmailAddressesMustBeUnique: No two users may have the same email

Supporting evidence:

- Name: test_unique_email
  Explanation: "None"
  Path: tests/test_important_stuff.py::test_unique_email
  Result: passed

## PasswordsMustBeGood: We don't want bad passwords

Supporting evidence:

- Name: test_password_strength
  Explanation: "None"
  Path: tests/test_important_stuff.py::test_password_strength
  Result: passedThis shows us all controls that are honored by the tests that we ran. Want to show your auditor that you’re checking important controls in your code? Now you have evidence.When run likepytest--honors-store-counts, pytest-honors saves the number of tests honoring each constraint. Later you can runpytest--honors-regression-fail, and if the coverage for any controls has decreased since the last test run, then pytest fails. Suppose an intern deletes thetest_unique_emailunit test. That results in the error:ValueError: ['Constraint MyControls.EmailAddressesMustBeUnique honorers count dropped from 1 to 0']You can integrate this in your CI pipeline and know that a rogue developer isn’t deleting the constraints you care about.ContributingContributions are very welcome. Tests can be run withtox, please ensure
the coverage at least stays the same before you submit a pull request.Especially appreciated, and requiring the least amount of coding experience, would be other constraint definitions so that new users have a pleasant “batteries included” experience.LicenseDistributed under the terms of theMITlicense, “pytest-honors” is free and open source software.IssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.