Commit Graph

197 Commits

Author SHA1 Message Date
Benjamin Schubert fbe3e29a55
Color the full diff that pytest shows as a diff (#11530)
Related to #11520
2023-10-24 08:42:21 -03:00
Reagan Lee 9bbfe995ee
Add more comprehensive set assertion rewrites (#11469)
Fixes #10617
2023-10-02 18:37:52 -03:00
Zac Hatfield-Dodds f4e3b4ad98 Drop Python 3.7 2023-06-30 14:55:42 -07:00
Zac Hatfield-Dodds 661b938fca Add encoding in more tests 2023-06-20 04:55:40 -07:00
Pierre Sassoulas b31db4809b
Avoid truncation when truncating means longer output (#10446)
Fixes #6267
2022-12-17 10:24:46 -03:00
Daniel Valenzuela b55e264a67 Fix test_raising_repr test
Closes #10473

Python <3.11 versions depend on `exceptiongroup>=1.0.0rc8`, and they released version `1.0.1`
6 days ago (2022/11/03) that as a side-effect changed the output of exceptions.
2022-11-09 19:43:10 -03:00
itxasos23 78c2c48c67
Handle NFC/NFD strings that normalize to the same string. (#10355)
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
2022-10-09 17:09:33 -07:00
Anthony Sottile 8fa775bcee fix comparison of dataclasses with `InitVar` 2022-04-08 19:51:05 -04:00
Samuel Colvin b75cbee290
Remove newlines from left/right operands with '-vv' (#9743)
The left/right operands produced when `verbose > 1` should not contain newlines, because they are used to 
build the `summary` string. The `assertrepr_compare` function returns a list of lines, and the summary is one of those lines and should not contain newlines itself. 

Fix #9742

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2022-03-19 11:55:39 +00:00
Bruno Oliveira fac8f284cd
Fix diff output for data types where `-v` would show less information (#9661)
Close #5192
2022-02-15 09:43:20 -03:00
Bruno Oliveira b79eff065e
Enable testing with Python 3.11 (#9511) 2022-02-11 15:20:42 +00:00
Hugo van Kemenade 61417b2551 Drop support for EOL Python 3.6 2021-12-30 13:25:34 +02:00
Yuval Shimon 0ea039db60 adding auto_detect=true test 2021-12-12 16:11:33 +02:00
Yuval Shimon 0c45065040 removing coverage on eq method 2021-12-12 15:39:30 +02:00
Yuval Shimon 897395afd5 fix 9326 2021-12-12 14:38:45 +02:00
David Szotten d5c020d8c5 always show full diff in ci
follow-up to #1314, for similar reasons

closes #9023
2021-08-19 20:17:43 +01:00
Karthikeyan Singaravelan 9a0f4e57ee Add support to display field names in namedtuple diffs. 2020-10-31 14:41:53 +02:00
Christine Mecklenborg 47ff911c8f Migrate test_assertion.py from testdir to pytester 2020-10-29 20:39:44 -05:00
Anthony Sottile 33d119f71a py36+: com2ann 2020-10-05 18:33:17 -07:00
Anthony Sottile 66bd44c13a py36+: pyupgrade: py36+ 2020-10-03 12:46:54 -07:00
Anthony Sottile 53b5f64b4b py36+: resolve py36 TODOs 2020-10-02 19:57:55 -07:00
Ran Benita 32bb8f3a63 Bump attrs requirement from >=17.4.0 to >=19.2.0
This allows us to remove the `ATTRS_EQ_FIELD` thing which is causing
some annoyance.
2020-09-27 13:17:59 +03:00
Ran Benita b8471aa527 testing: fix some docstring issues
In preparation for enforcing some docstring lints.
2020-08-03 10:10:43 +03:00
Ran Benita be656dd4e4 typing: set disallow_any_generics
This prevents referring to a generic type without filling in its generic
type parameters.

The FixtureDef typing might need some more refining in the future.
2020-08-01 20:39:15 +03:00
Vlad-Radz 678c1a0745
assertion: improve diff output of recursive dataclass/attrs
Co-authored-by: Vlad <uladzislau.radziuk@nordcloud.com>
2020-07-08 19:04:56 +03:00
Gleb Nikonorov 33de350619 parametrize test_warn_missing for a cleaner test 2020-06-21 10:26:36 -04:00
Gleb Nikonorov fe68c58698 add test_warn_missing case for --assert=plain 2020-06-20 13:06:41 -04:00
Gleb Nikonorov a9d50aeab6 remove extra whitespace 2020-06-20 12:18:55 -04:00
Gleb Nikonorov ac89d6532a replace stderr warnings with the warnings module 2020-06-20 12:15:58 -04:00
Bruno Oliveira c229d6f46f Fix mypy checks 2020-06-09 14:48:49 -03:00
Ran Benita 09988f3ed1 Update testing/test_assertion.py 2020-06-09 14:39:40 -03:00
ibriquem e2e7f15b71 Make dataclasses/attrs comparison recursive, fixes #4675 2020-06-09 14:39:40 -03:00
Ran Benita 54ad048be7 Enable check_untyped_defs mypy option for testing/ too 2020-06-05 11:34:20 +03:00
Ran Benita 20956b2f4e Remove some no-longer-needed compat code in test_assertion 2020-04-08 21:35:42 +03:00
Daniel Hahler 48c9f556ef
Fix tests: use explicit syspathinsert where tests might hang (#7008)
Use `testdir.syspathinsert()` with multiprocessing tests:

- test_chained_exceptions_no_reprcrash
- test_exception_handling_no_traceback

This only works currently because `_importtestmodule` changes `sys.path`
as a side-effect.

It appears to be only required on Windows though - likely due to the
multiprocessing method used there.
2020-04-04 12:33:15 +02:00
Daniel Hahler bce1d40fb0
tests: harden test_reprcompare_notin, factor out callop (#6764)
* tests: assertion: factor out `callop`, typing

* tests: harden test_reprcompare_notin
2020-03-08 01:23:19 +01:00
Daniel Hahler 6a7df7f031
test_assertion: harden/improve test_{text_diff,unicode} (#6806) 2020-02-24 15:19:08 +01:00
Daniel Hahler 1baeefc2fd test_reprcompare_whitespaces: use callequal 2020-02-22 13:15:17 +01:00
Daniel Hahler d89b5057ca
assertrepr_compare: provide more info (location) with exceptions (#6728) 2020-02-14 02:17:05 +01:00
Bruno Oliveira e6ea9edffe
Merge pull request #6673 from sscherfke/features
Reverse / fix meaning of "+/-" in error diffs
2020-02-12 15:05:38 -03:00
Stefan Scherfke d59adc61f9 Reverse / fix meaning of "+/-" in error diffs
The convention is "assert result is expected".  Pytest's error diffs now
reflect this. "-" means that sth. expected is missing in the result and
"+" means that there are unexpected extras in the result.

Fixes: #3333
2020-02-10 21:12:37 +01:00
Daniel Hahler aa0328782f
assertion: save/restore hooks on item (#6646) 2020-02-04 02:56:23 +01:00
Daniel Hahler e7444bbd5e tests: remove unnecessary `-rw` option
Warnings are enabled by default, which is tested by `test_getreportopt`.
2020-01-23 11:37:19 +01:00
Daniel Hahler 5049e25a6a tests: cleanup unused fixtures 2020-01-16 21:12:48 +01:00
Daniel Hahler 6ddf7c3d42 pytester: Hookrecorder: improve assertoutcome
Before:

        def assertoutcome(self, passed: int = 0, skipped: int = 0, failed: int = 0) -> None:
            realpassed, realskipped, realfailed = self.listoutcomes()
            assert passed == len(realpassed)
    >       assert skipped == len(realskipped)
    E       assert 1 == 0
    E        +  where 0 = len([])

After:

    >       reprec = testdir.inline_run(testpath, "-s")
    E       AssertionError: ([], [], [<TestReport 'nodeid' when='call' outcome='failed'>])
    E       assert {'failed': 1, 'passed': 0, 'skipped': 0} == {'failed': 0, 'passed': 0, 'skipped': 1}
2019-11-13 13:48:20 +01:00
Daniel Hahler cc503c1821 _compare_eq_iterable: use AlwaysDispatchingPrettyPrinter
This fixes/removes the previous hack of re-trying with minimum width,
which fails short when it splits strings.

This inherits from `pprint.PrettyPrinter` to override `_format` in a
minimal way to always dispatch, regardless of the given width.

Code ref: 5c0c325453/Lib/pprint.py (L170-L178)
2019-11-08 04:07:09 +01:00
Daniel Hahler 5c00226847 test_iterable_full_diff: use test ids 2019-11-07 12:24:01 +01:00
Daniel Hahler ce3d431002 assert: fix _compare_eq_iterable: re-format both sides
Follow-up to 946434c61 (#5924).

Before this patch the test would look like this:

    {'env': {'sub...s wrapped'}}}} == {'env': {'sub...}}}, 'new': 1}
    Omitting 1 identical items, use -vv to show
    Right contains 1 more item:
    {'new': 1}
    Full diff:
      {
       'env': {'sub': {'long_a': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
    -                  'sub1': {'long_a': 'substring '
    +                  'sub1': {'long_a': 'substring that gets wrapped'}}},
    ?                                                +++++++++++++++++ ++++
    +  'new': 1,
    -                                     'that '
    -                                     'gets '
    -                                     'wrapped'}}},
      }
2019-11-06 11:23:15 +01:00
Daniel Hahler fb90259460 test_assertion: improve mock_config 2019-10-11 04:19:07 +02:00
Daniel Hahler 946434c610 Improve full diff output for lists
Massage text input for difflib when comparing pformat output of
different line lengths.

Also do not strip ndiff output on the left, which currently already
removes indenting for lines with no differences.

Before:

    E   AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...]
    E     Right contains 3 more items, first extra item: ' '
    E     Full diff:
    E     - ['version', 'version_info', 'sys.version', 'sys.version_info']
    E     + ['version',
    E     +  'version_info',
    E     +  'sys.version',
    E     +  'sys.version_info',
    E     +  ' ',
    E     +  'sys.version',
    E     +  'sys.version_info']

After:

    E   AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...]
    E     Right contains 3 more items, first extra item: ' '
    E     Full diff:
    E       [
    E        'version',
    E        'version_info',
    E        'sys.version',
    E        'sys.version_info',
    E     +  ' ',
    E     +  'sys.version',
    E     +  'sys.version_info',
    E       ]
2019-10-08 15:27:51 +02:00