Skip to content

Releases: approvals/ApprovalTests.Python

inline approvals bug fixes

17 Mar 19:34
Compare
Choose a tag to compare
  • options.inline can now be created outside of the test method
  • renamed quiet_reporter to report_quietly
    • kept link to old name for backwards compatibility
  • fixed bug in quiet_reporter and InlineReporter where they were throwing the wrong exception on failure

inline approvals works with unittest

10 Mar 18:33
Compare
Choose a tag to compare

fixed a bug where inline was working with pytest but not unittest

verify_all_combinations_with_labeled_inputs

03 Mar 19:38
Compare
Choose a tag to compare

You can now do this:

    def test_with_labeled_input(self) -> None:
        verify_all_combinations_with_labeled_input(
            lambda a,b: a+b+1,
            arg1=(1, 3),
            arg2=(2, 4),
        )

and it will produce:

(arg1: 1, arg2: 2) => 4
(arg1: 1, arg2: 4) => 6
(arg1: 3, arg2: 2) => 6
(arg1: 3, arg2: 4) => 8

verify_all(header=none)

25 Feb 17:28
Compare
Choose a tag to compare

Breaking Change

verify_all with an empty head will no longer add 2 blank lines at the beginning of the file

Parse Inputs from docstring

11 Feb 19:25
Compare
Choose a tag to compare

This allows for inline approvals to get the inputs from the approved docstring.
(more coming soon)
Here's an example where the inputs (a,b,c) are gathered from the docstring:

from approvaltests.inline.parse_docstring import parse_docstring

def test_uppercase():
    """
    a -> A
    b -> B
    c -> C
    """
    verify("\n".join([ f"{a} -> {a.upper()}" for a in parse_docstring()]), options=Options().inline())

support alternative naming patterns in pytest

28 Jan 19:02
Compare
Choose a tag to compare

Fixes #155

by default pytest requires your functions to start with test_

this is configurable in pytest was not supported by Approval Tests
it is now supported in Approval Tests

Inline Reporter handle single and double quotes

03 Dec 19:55
Compare
Choose a tag to compare
. d for future

Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com>
Co-Authored-By: Michael R Wolf <MichaelRWolf@att.net>
Co-Authored-By: Susan Fung <38925660+susanfung@users.noreply.github.com>
Co-Authored-By: Nitsan Avni <nitsanav@gmail.com>

Inline Approvals

26 Nov 21:29
Compare
Choose a tag to compare

You can now use inline approvals by adding

verify(result, options=Options().inline())

This will use the test method docstring as the expected result instead of a separate .approved.txt file.

The current reporter has limited support for Python, it will be improved.

Exceptions and Help messages on duplicate verify() calls.

15 Oct 20:22
Compare
Choose a tag to compare

ApprovalTests only wants one call to verify() per test.

There are ways to go around this but if you call verify where it would want the exact same file name twice, it will now throw an exception.
This will make it easier for people to not be confused as most other testing frameworks allow you to put multiple assertions in the same test.

Backwards compatibility

There are some situations where you want to check that two different processes produce the same result.
Calling verify multiple times in the same test can be a way to do this.
If you want to do that, we have provided the following:

approvals.settings().allow_multiple_verify_calls_for_this_method()

`verify_as_json()` creates `.json` files instead of `.txt`

27 Aug 19:48
Compare
Choose a tag to compare

verify_as_json() creates .json files instead of .txt

This is a BREAKING CHANGE.

There are two ways to fix this.

1. re-approve the .json files

Either:

  1. Rename the .txt files to .json
  2. Move them over in your diff tool
  3. Use ReporterThatAutomaticallyApproves
    verify_as_json(result, options=Options().with_reporter(ReporterThatAutomaticallyApproves()))
  4. Use ReporterByCopyMoveCommandForEverythingToClipboard + paste into your terminal
    verify_as_json(result, options=Options().with_reporter(ReporterByCopyMoveCommandForEverythingToClipboard()))

2. Keep your .txt files backwards compatible

verify_as_json(result, options=Options().for_file.with_extension(".txt"))