GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - approvals/ApprovalTests.Python: ApprovalTests for python

BranchesTags
Open more actions menu

Latest commit

 

History

2,768 Commits
2,768 Commits

Folders and files

NameName
Last commit message
Last commit date
.claude
.claude
 
 
.github
.github
 
 
.habit-hooks
.habit-hooks
 
 
.vscode
.vscode
 
 
approval_utilities
approval_utilities
 
 
approvaltests
approvaltests
 
 
docs
docs
 
 
internal_documentation
internal_documentation
 
 
setup
setup
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.gitpod.yml
.gitpod.yml
 
 
.jscpd.json
.jscpd.json
 
 
.mise.toml
.mise.toml
 
 
.pre-commit-config.yaml
.pre-commit-config.yaml
 
 
.pylintrc
.pylintrc
 
 
.python-version
.python-version
 
 
AGENTS.md
AGENTS.md
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
README.md
README.md
 
 
TODO.md
TODO.md
 
 
__init__.py
__init__.py
 
 
build_and_test
build_and_test
 
 
build_and_test.cmd
build_and_test.cmd
 
 
build_and_test_fast
build_and_test_fast
 
 
build_and_test_fast.cmd
build_and_test_fast.cmd
 
 
clean_and_build.cmd
clean_and_build.cmd
 
 
install.windows.ps1
install.windows.ps1
 
 
mdsnippets.json
mdsnippets.json
 
 
mlc_config.json
mlc_config.json
 
 
mypy.ini
mypy.ini
 
 
new_virtual_desktop.cmd
new_virtual_desktop.cmd
 
 
pin_requirements_to_minimum_acceptable_version.py
pin_requirements_to_minimum_acceptable_version.py
 
 
pyproject.toml
pyproject.toml
 
 
pytest.ini
pytest.ini
 
 
requirements.dev.txt
requirements.dev.txt
 
 
requirements.prod.extras.txt
requirements.prod.extras.txt
 
 
requirements.prod.required.txt
requirements.prod.required.txt
 
 
requirements.prod.txt
requirements.prod.txt
 
 
requirements.test.txt
requirements.test.txt
 
 
requirements.txt
requirements.txt
 
 
ruff.toml
ruff.toml
 
 
run_fixer.cmd
run_fixer.cmd
 
 
run_mdsnippets
run_mdsnippets
 
 
run_mdsnippets.cmd
run_mdsnippets.cmd
 
 
run_tests_and_tidy_code.sh
run_tests_and_tidy_code.sh
 
 
start_todo.ps1
start_todo.ps1
 
 
test__mypy_accepts_our_packages.py
test__mypy_accepts_our_packages.py
 
 
tidy_code
tidy_code
 
 
tidy_code.cmd
tidy_code.cmd
 
 
version.py
version.py
 
 
windows.ps1
windows.ps1
 
 

Repository files navigation

ApprovalTests.Python

Contents

  • What can I use ApprovalTests for?
  • Getting Started
    • What Are Approvals
    • New Projects
      • Minimal Example Tutorial
    • Adding to Existing Projects
  • Overview
    • Example using pytest
    • Example using unittest
    • Example using CLI
      • Usage
      • Argument Definitions
  • Reporters
  • Support and Documentation
    • Missing Documentation?
    • Dependencies
      • Python
      • Required packages
      • Extra packages
  • For developers
    • Weekly Ensemble
    • Pull Requests

Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid testing.
approvaltests is the ApprovalTests port for Python.

For more information see: www.approvaltests.com.

PyPI version Python versions Build Status Build Status Build Status Discord

What can I use ApprovalTests for?

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

Adding to Existing Projects

From pypi:

pip install approvaltests

Overview

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)

snippet source | anchor

Example using unittest

import unittest

from approvaltests.approvals import verify


class GettingStartedTest(unittest.TestCase):
    def test_simple(self) -> None:
        verify("Hello ApprovalTests")


if __name__ == "__main__":
    unittest.main()

snippet source | anchor

This example has the same behaviour as the pytest version, but uses the built-in test framework unittest instead.

Example using CLI

You can invoke a verify() call from the command line. This allows invoking python approvals from any other stack via subprocesses.

Usage

python -m approvaltests --test-id hello --received "hello world!"

or

python -m approvaltests -t hello -r "hello world!"

or

echo "hello world!" | python -m approvaltests -t hello

Argument Definitions

  • --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.

  • Intro to reporters
  • How to select a reporter
  • How to create a custom reporter

Support and Documentation

  • Documentation

  • GitHub: https://github.com/approvals/ApprovalTests.Python

  • ApprovalTests Homepage: http://www.approvaltests.com

Missing Documentation?

If there is documentation you wish existed, please add a page request to this issue.

Dependencies

Python

ApprovalTests is tested on the following Python versions: 3.11, 3.12, 3.13, 3.14, 3.15.

For older versions of Python, either:

  • use an older version of ApprovalTests, or
  • use TextTest, or
  • hire us to help

Required packages

These dependencies are always required for approvaltests

pytest>=8.0.0
empty-files>=0.0.3
typing_extensions>=4.16.0

snippet source | anchor

Extra packages

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

snippet source | anchor

For developers

Weekly Ensemble

The best way to contribute is to join our weekly mob/ensemble.

Pull Requests

Pull requests are welcomed, particularly those accompanied by automated tests.

To run the self-tests: ./build_and_test.sh

This will run the self-tests on several python versions. We support python 3.10 and above.

All pull requests will be pre-checked using GitHub actions to execute all these tests. You can see the results of test runs here.

About

ApprovalTests for python

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

216 stars

Watchers

12 watching

Forks

56 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.