Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid testing. approvaltests is the ApprovalTests port for Python.
You can use ApprovalTests to verify objects that require more than a simple assert including long strings, large arrays,
and complex hash structures and objects. ApprovalTests really shines when you need a more granular look at the test
failure. Sometimes, trying to find a small difference in a long string printed to STDOUT is just too hard!
ApprovalTests solves this problem by providing reporters which let you view the test results in one of many popular diff
utilities.
Getting Started
What Are Approvals
If you need to gain a better understanding or are new to this concept, start here.
New Projects
If you are starting a new project, we suggest you use the Starter Project.
You can just clone this and go. It's great for exercises, katas, and green field projects.
Minimal Example Tutorial
If this is first time approvaltesting in python, consider starting here: Minimal Example Tutorial
Approvals work by comparing the test results to a golden master. If no golden master exists you can create a snapshot
of the current test results and use that as the golden master. The reporter helps you manage the golden master.
Whenever your current results differ from the golden master, Approvals will launch an external application for you to
examine the differences. Either you will update the master because you expected the changes and they are good,
or you will go back to your code and update or roll back your changes to get your results back in line with the
golden master.
Example using pytest
from approvaltests.approvals import verify
def test_simple() -> None:
result = "Hello ApprovalTests"
verify(result)
--test-id or -t: Test identifier used to name the approved.txt and received.txt files for the test.
--received or -r: The output of the program under test (a string) that is passed to the verify method.
stdin: Instead of providing a received argument, you may use stdin.
Reporters
A reporter controls how ApprovalTests handles a failing test result.
The default behavior is to open a diff tool showing what you received vs what was approved.
You can use this diff tool to change the approved to make the test pass the next time you run it.
Reporters also have more advanced usages.
These dependencies are needed if you are going to use the related functionality.
If you want the bare minimum you can use the pypi project
approvaltests_minimal.
# For reporters.clipboard_reporter.ClipboardReporter
pyperclip>=1.5.29
# For approvals.verify_html()
beautifulsoup4>=4.9.0
# For pairwise_combinations.get_best_covering_pairs()
allpairspy>=2.1.0
# For utilities.logging.logging_approvals.verify_logging()
testfixtures >= 7.1.0, < 12
mock >= 5.1.0
# For reporters.intellij_reporter.IntelliJReporter
psutil >= 5.9.0