Commit Graph

2978 Commits

Author SHA1 Message Date
Ronny Pfannschmidt 24ef7c98e8
Merge pull request #10343 from RonnyPfannschmidt/fix-10342-warn-explicit-add-location
fix #10342: put location into warning exceptions
2022-10-07 13:04:32 +02:00
Ronny Pfannschmidt 7a15bad89b
Update src/_pytest/warning_types.py
Co-authored-by: Florian Bruhin <me@the-compiler.org>
2022-10-07 12:46:40 +02:00
Florian Bruhin 72cac9b1af Mark tryfirst/trylast as deprecated in their docs.
Follow-up to #9118
2022-10-07 12:16:53 +02:00
Ronny Pfannschmidt 14919c4bbb fix #10342: put location into warning exceptions
as the warning systems own warn_explicit looses the information
we add them explicitly to the warning exceptions
2022-10-06 11:44:05 +02:00
Thierry Moisan 06007de7ba
Fix a few broken links in the documentation 2022-10-05 10:24:55 -04:00
Adam Turner 594413e8f0
Use an explicit encoding when opening `os.devnul`
Although slightly pointless, this avoids an `EncodingWarning` in Python 3.10
or greater when running under the `-X warn_default_encoding` flag.
2022-09-30 23:43:27 +01:00
Ronny Pfannschmidt ae9dbf5006 add docstring to warn_explicit_for 2022-09-20 16:24:32 +02:00
Ronny Pfannschmidt 7e8a4849d8 unify option extraction for legacy hook marks 2022-09-20 16:24:32 +02:00
Ronny Pfannschmidt e3294398d6 simplify typing for legacy hook mark support 2022-09-20 16:24:23 +02:00
Ronny Pfannschmidt b1fb9a9c8d handle non-true options in hookspec warning 2022-09-20 16:22:26 +02:00
Ronny Pfannschmidt 0fdacb6db5 deprecate hook configuration via marks/attributes
fixes #4562
2022-09-20 16:22:26 +02:00
Gergely Kalmár adaa463ee3
Ignore editable installation modules (#10231)
Fixes #10230
2022-08-26 09:46:47 -03:00
John Litborn 69f2855cc8
fallback to native traceback when handling ExceptionGroup (take 2) [SQUASH] (#10209)
* Squashed commit of the following:

commit 41d339c46763bbe26123e1e6504b6e32290e33e1
Author: Cheukting <cheukting.ho@gmail.com>
Date:   Thu Jun 23 17:01:04 2022 +0800

    test in all py versions

commit b3572a5a12672228c3276fc8c8e05980dfb7888a
Author: Cheukting <cheukting.ho@gmail.com>
Date:   Thu Jun 23 16:41:06 2022 +0800

    add test

commit 7166a2a51e4f99046b028b663c193d8b558c7fd4
Author: Cheukting <cheukting.ho@gmail.com>
Date:   Thu Jun 23 16:00:07 2022 +0800

    update changelog

commit b958c73d489157f0c0d4e46425083a5e2e2bc851
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Thu Jun 23 07:50:52 2022 +0000

    [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

commit ea7f376c6ca37c40c83df0e4a1cfaaedb34bae91
Author: Cheukting <cheukting.ho@gmail.com>
Date:   Thu Jun 23 15:48:21 2022 +0800

    Fix MyPy

commit 97469beb1da40257e9a061a5e19548546c9312c4
Author: Cheukting <cheukting.ho@gmail.com>
Date:   Thu Jun 23 15:03:48 2022 +0800

    fix if ExceptionGroup not exist

commit 84e553642cd69b4d499231d733df91ebfa84c7ad
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Thu Jun 23 03:43:27 2022 +0000

    [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

commit 76bbef449b88bbd74fb5cca3b5293337a624ef03
Author: Cheukting <cheukting.ho@gmail.com>
Date:   Thu Jun 23 11:40:41 2022 +0800

    adding changelog

commit db82bebc5a4969e2083adcd97bdfd2a63bb17d98
Author: Cheukting <cheukting.ho@gmail.com>
Date:   Thu Jun 23 11:33:10 2022 +0800

    fall back to native when handeling to exception groups

* Typed ExceptionGroupTypes and changed to BaseExceptionGroup, fixed exceptionchain (excinfo->excinfo_, set reprcrash. Extended tests, though they're wip.

* added exceptiongroup to pre-commit-config, moved away from tuple to directly defining BaseExceptionGroup, added block comment, added match line for inner exception, changked mark.skipif to importorskip to not need top-level import, changed tox.ini a bit - only uncovered should now be py37 without exceptiongroup, due to hypothesis

* added py311-exceptiongroup to github CI, exceptiongroup is now a hard dependency on py<3.11, renamed bad variable names

* added use_coverage to ubuntu-py311

* import BaseExceptionGroup with explicit version check instead of try/catch

* removed from CI, added comments to tox and pre-commit
2022-08-17 09:16:32 -07:00
Tatiana Ovary 3039391b83
Update documentation on how pytest.warns affects DeprecationWarning #9291 (#10141)
Co-authored-by: Dani Sancas <lord.sancas@gmail.com>

On-behalf-of: @clarityai-eng <tech@clarity.ai>

Signed-off-by: Tatiana Ovary <tatiana.ovary@clarity.ai>
2022-08-17 11:44:58 -03:00
Ran Benita b6eaf319d1
Merge pull request #10219 from bluetech/parametrize-argnames-type
mark: allow any Sequence[str] for parametrize(argnames), not just list/tuple
2022-08-15 19:59:45 +03:00
Bruno Oliveira 2e7c718373
Add reference to the Where to patch docs in monkeypatch.setattr (#10217)
This should help users with the common issue of patching the wrong place.

Also took the opportunity of using proper links in the monkeypatch introduction.

Related to #10216

Co-authored-by: Ran Benita <ran@unusedvar.com>
2022-08-15 13:55:19 -03:00
Ran Benita 67e29d2548 mark: allow any Sequence[str] for parametrize(argnames), not just list/tuple
The main motivation for this change is to simplify the type shown in
code editors -- `Sequence[str]` is easier to follow than
`Union[list[str], tuple[str, ...]]`.

It also permits using other types if desired. It might lead to problems
if someone uses some oddball sequence type, but hopefully they won't do
that.
2022-08-15 19:38:09 +03:00
Ran Benita 63d2f7f7f8
Merge pull request #9248 from bluetech/sphinx4
doc: support sphinx 5
2022-08-13 22:35:55 +03:00
Sviatoslav Sydorenko 739322af03
Mention `monkeypatch.context()` in the docs (#10192)
In addition:

* Improve the docs a bit with links.
* Recommend `context()` instead of `undo()`.
2022-08-13 16:07:27 -03:00
Ran Benita beae7fd0ba doc: workaround for ugly API docs for overloaded functions with new Sphinx
New Sphinx added support for overloads and always displays them all with
full type annotations etc. This regresses the API reference for
overloaded functions like `fixture()`, `warns()`, `raises()` and friends
to become impossible to read.

I tried various workarounds but none worked except this one.
2022-08-13 21:46:49 +03:00
Ran Benita 7431750bb6 doc: have tighter control on what autodoc shows
New versions of sphinx starting showing `__init__` parameters even when
we don't want them to show because they are private (have `_ispytest`
argument).

The only working solution I found was to switch to
`autodoc_typehints_description_target = "documented"` and explicitly
document parameters for which we want to show the types. It's a little
tedious and repetitive in some simple cases, but overall it results in
nicer API docs.
2022-08-13 21:46:49 +03:00
Ran Benita cb7f5ed3b1 doc: require sphinx 5
Fix #9836.
2022-08-13 21:45:54 +03:00
holesch cc0092b9d8
JUnit XML: Escape error messages in setup/teardown (#10190)
Co-authored-by: Holesch, Simon (BSH) <simon.holesch@bshg.com>
2022-08-12 11:11:03 +02:00
Brandon Chinn 4d430ea6ff
Fix partially unknown type (#10204) 2022-08-12 11:08:39 +02:00
Thomas Grainger 58cf20edf0
Update :class:`pytest.PytestUnhandledCoroutineWarning` to a deprecation; it will raise an error in pytest 8. [SQUASH] (#10012)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2022-08-08 10:14:49 +01:00
Robert O'Shea 1c31a7e659
Added file-like methods to DontReadFromInput (#10173)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

Fixes #10150
2022-07-31 13:44:02 +00:00
Wolfremium 70cac3d464
Explicit note that tmpdir fixture is discouraged in favour of tmp_path #9937 (#10138)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Co-authored-by: kevin.hierro-ext <kevin.hierro-ext@clarity.ai>
Co-authored-by: Dani Sancas <lord.sancas@gmail.com>
2022-07-15 08:40:18 -03:00
Nipunn Koorapati c1d134172c
Add typing for FixtureRequest.param (#10133)
For now, mark it as Any until #8073 is solved

Fixes #9514
2022-07-14 20:36:05 -03:00
Bruno Oliveira 334d6514c6 Fix mypy pre-commit run
This started to fail recently with:

```
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

src/_pytest/assertion/rewrite.py:284: error: Returning Any from function declared to return "TraversableResources"  [no-any-return]
Found 1 error in 1 file (checked 219 source files)
```

Not sure why that started failing, but seems like ignoring that error specifically is OK.
2022-07-11 08:27:09 -03:00
Anthony Sottile 4cd0322ca1 replace atomicwrites with os.replace 2022-07-08 18:36:10 -07:00
Ronny Pfannschmidt 966d4fb3e4
Merge pull request #10051 from EmptyRabbit/dev_main
Fix stage caplog records not clear
2022-07-08 07:46:10 +02:00
Alice Purcell c34eaaaa1c Pass importmode to import_path in DoctestModule
This allows doctest to be used with namespace modules
2022-06-29 14:38:59 +01:00
Bruno Oliveira bd642fac70 Do not call tearDown for skipped unittest.TestCases with --pdb
Fix #10060
2022-06-27 10:33:37 -03:00
Bruno Oliveira f92c4a77ad Use PurePath directly instead of os.path.sep in rewrite.py
Given we are already creating a `PurePath`, just pass the parts directly to it.

This avoids using `os.path.sep`, that although is an official API, seems not to be available in all systems.

Fix #9791
2022-06-26 21:29:05 -03:00
Bruno Oliveira aafac5578c
Merge pull request #10056 from paulreece/fixture-path-doc-fix
Added Docstring description for the Path property of FixtureRequest #9975
2022-06-25 20:55:23 -03:00
zx.qiu f29f79e39f Use records.clear() in LogCaptureHandler when caplog.clear() 2022-06-24 23:04:04 +08:00
zx.qiu c7e784f95d Fix stage caplog records not clear
Closes #9877
2022-06-24 23:03:37 +08:00
Anthony Sottile 74691346bd fix some typos to ensure pre-commit.ci fixes main 2022-06-22 08:29:02 -07:00
Paul Reece 5a9536cf42 Added Docstring description for the Path property of the FixtureRequest class. 2022-06-17 11:52:18 -04:00
Chris Wheeler fab696dcd1
Add support for .pytest.ini as an alternative to pytest.ini
Closes #9987
2022-06-14 08:24:35 -03:00
Zach OBrien 96412d19ab
Fix representation of tuples in approx
Closes #9917
2022-06-14 06:54:32 -03:00
Neil Girdhar 5adfb0e187
Use symbolic NoReturn as a type annotation (#10018)
Use symbolic NoReturn as a type annotation
2022-06-03 07:59:48 -03:00
Bruno Oliveira 130c954bb1
Merge pull request #9904 from johnkangw/notes_update 2022-05-31 16:35:29 -03:00
Hugo van Kemenade e54c6a1362
Document the --code-highlight default (#9883)
Also normalized all help text using the patterns:

* `One sentence help text`
* `First sentence of help. Second sentence of help.`
2022-05-31 16:32:51 -03:00
Ronny Pfannschmidt c533015c56
Merge pull request #9880 from jparise/getfixturemarker-attr
Use safe_getattr() in getfixturemarker()
2022-05-30 05:54:40 +02:00
Zac Hatfield-Dodds a47e91e077
Merge pull request #9893 from jparise/pytester-mkdir-path 2022-05-27 20:51:50 -07:00
Zac Hatfield-Dodds 420dc7824b
Merge pull request #9990 from petebman/improve_getfixturevalue_error_message 2022-05-27 20:40:55 -07:00
Cheuk Ting Ho c988e49af6
Warn when test functions return other than None (#9956)
Closes #7337
2022-05-25 09:48:02 -03:00
Jon Parise 8ac6dce2c7
Add shell-style wildcard support to 'testpaths' (#9897)
This is especially useful for large repositories (e.g. monorepos) that
use a hierarchical file system organization for nested test paths.

    src/*/tests

The implementation uses the standard `glob` module to perform wildcard
expansion in Config.parse().

The related logic that determines whether or not to include 'testpaths'
in the terminal header was previously relying on a weak heuristic: if
Config.args matched 'testpaths', then its value was printed. That
generally worked, but it could also print when the user explicitly used
the same arguments on the command-line as listed in 'testpaths'. Not a
big deal, but it shows that the check was logically incorrect.

Now that 'testpaths' can contain wildcards, it's no longer possible to
perform this simple comparison, so this change also introduces a public
Config.ArgSource enum and Config.args_source attribute that explicitly
names the "source" of the arguments: the command line, the invocation
directory, or the 'testdata' configuration value.
2022-05-24 10:20:51 +02:00
Pete Baughman 0e62861e84 Improve error message in getfixturevalue 2022-05-23 17:54:22 +00:00
Bruno Oliveira a1ed6839e3 Refer to py.path.local instead of LEGACY_PATH constant for better docs 2022-05-17 08:09:21 -03:00
Ezio Melotti 296b642eb3
Fix rst markup in TempdirFactory's docstring. 2022-05-17 07:29:32 +02:00
sommersoft 56c266640e
Do not truncate crash messages in short test summary on CI (#9933)
Closes #9920
2022-05-13 08:15:52 -03:00
Bruno Oliveira 69fb79e741
Add colors to summary (#9875)
Fix #9873
2022-05-12 09:55:40 -03:00
Zac Hatfield-Dodds ccdee08ddd
Merge pull request #9911 from bkeyvani/fix-issue-8646 2022-05-10 23:53:40 -07:00
Tim Hoffmann 231e220635 Move documentation contents from reference.rst to docstrings
It's better to have the documentation in one place, instead
of having some in the docstring and some additional
information added to the reference documentation in
`reference.rst`.
2022-05-10 20:04:25 +02:00
Babak Keyvani 31a9c5c667 improve `pytest.raises` - cont'd
a few more iterations on error message and related tests.
2022-05-09 21:15:02 -04:00
Peyman Salehi 2f62e6ec96
Fix default encoding in cacheprovider 2022-05-03 20:56:46 +04:30
Shantanu 2ba8fd5bc5
Re-export importlib.metadata from _pytest.compat (#9906)
I'm fixing a bug in mypy's --no-implicit-reexport logic in
https://github.com/python/mypy/pull/12704 and mypy-primer flagged this
2022-05-01 10:05:41 +03:00
Babak Keyvani 3444d35c54 improve `pytest.raises` 2022-04-30 17:56:36 -06:00
johnkangw 97383d2d5d
Mention use of re_assert for strings in approx docs 2022-04-30 17:20:31 -06:00
Jon Parise f6db7ae749 Let mkdir() and mkpydir() receive PathLike names
These pytester utility methods were annotated to only receive `str`
names, but they naturally support os.PathLike values, as well.

This makes writing some pytester calls a little nicer, such as when
creating a directory based on a `.joinpath()` call. We previously needed
to cast that intermediate value to a `str`.
2022-04-25 17:21:15 -07:00
Jon Parise e598429c73 Use safe_getattr() in getfixturemarker() 2022-04-22 14:47:36 -07:00
Tobias Diez 7df405747a
Merge branch 'pytest-dev:main' into patch-1 2022-04-22 12:11:03 +02:00
pre-commit-ci[bot] 12971a37e1 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2022-04-20 18:23:04 +00:00
Paul Müller 715d0ca9d0
cleanup 2022-04-20 20:21:44 +02:00
pre-commit-ci[bot] ac9b65d890 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2022-04-20 18:15:49 +00:00
Paul Müller 988197c795
fix: move 'import getpass' statement to try-clause 2022-04-20 20:09:37 +02:00
Hugo van Kemenade 5800d39053
Increase stacklevel to point at user's code (#9869)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-20 13:07:10 -03:00
Shantanu 2e8a319828
Use tomllib on Python 3.11 (#9741) 2022-04-17 21:11:17 +03:00
Anthony Sottile 8fa775bcee fix comparison of dataclasses with `InitVar` 2022-04-08 19:51:05 -04:00
Tobias Diez 63c7338028
Fix rename issue 2022-03-27 16:56:23 +02:00
pre-commit-ci[bot] 0eae340e13 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2022-03-27 14:41:12 +00:00
Tobias Diez 1f10c59cd3
Clarify error message in case no collectors are found for a file 2022-03-27 16:30:57 +02:00
Ronny Pfannschmidt e9dd3dffab
Enhance errors for exception/warnings matching (#8508)
Co-authored-by: Florian Bruhin <me@the-compiler.org>
2022-03-20 23:32:39 -03:00
Kian Eliasi 3297bb24a9
Remove unnecessary numpy import (#9798)
Fix #9726
2022-03-21 00:01:59 +00: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
Florian Best 8f64a39d0a [style]: fix typo in docstring 2022-03-18 22:00:14 +01:00
Ran Benita 1d70b022f0 config: restore pre-pytest 7.1.0 confcutdir exclusion behavior
The change from `path not in confuctdir.parents` to the `relative_to`
check in 0c98f19231 broke picking up
conftest files when running against an installed package/site-packages.
See the issue for more details.

Fix #9767.
2022-03-16 22:55:06 +02:00
pre-commit-ci[bot] d52a6e6074
[pre-commit.ci] pre-commit autoupdate (#9769)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/asottile/reorder_python_imports: v2.7.1 → v3.0.1](https://github.com/asottile/reorder_python_imports/compare/v2.7.1...v3.0.1)
- [github.com/asottile/pyupgrade: v2.31.0 → v2.31.1](https://github.com/asottile/pyupgrade/compare/v2.31.0...v2.31.1)
- [github.com/pre-commit/mirrors-mypy: v0.931 → v0.940](https://github.com/pre-commit/mirrors-mypy/compare/v0.931...v0.940)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix mypy errors

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-16 21:34:40 +02:00
Ran Benita 2bec21ef5f
Merge pull request #9756 from ajberdy/main
Fixed typo in pytester docs.
2022-03-16 21:32:42 +02:00
Rowin e75cdae2bc
Typo correction
A word was missing in the docstring of the warns function.
2022-03-14 13:26:17 +01:00
Aaron Berdy f3053017b9 fix typo in pytester docs 2022-03-12 14:44:52 -08:00
Bruno Oliveira e38d1cac48 Improve error message for malformed pyproject.toml files
Including the file name is enough to let the user know what the problem is.

The same is not needed for `.ini` files because the error message includes the path to the file by default.

Fix #9730
2022-03-05 08:59:28 -03:00
Bruno Oliveira f943d1944a pytester now requests monkeypatch instead of creating its own instance
It is tempting to use `monkeypatch` to replace the other mechanisms in pytester which change global
state: `CwdSnapshot`, `SysModulesSnapshot`, `SysPathsSnapshot`, however those are more delicate
than they look at first glance so leaving those alone for now.

Close #9708
2022-03-04 08:58:44 -05:00
Bruno Oliveira 5f3d94c47e
Disallow unordered sequences in pytest.approx (#9709)
Fix #9692
2022-02-24 10:16:35 -03:00
Ran Benita 7b6e477e2f
Revert "Deprecate raising unittest.SkipTest to skip tests during collection" (#9710)
This reverts commit 25e657bfc1.

Turns out that this *is* a working unittest feature, which pytest should
support, so undo the deprecation.
2022-02-23 15:59:54 +02:00
Bruno Oliveira 9af3e23695
Expand warnings output for ResourceWarning (#9682)
Fix #9644
2022-02-15 13:00:50 +00:00
Ran Benita bdbad91493
Merge pull request #9546 from bluetech/fixturedef-attr-doc
fixtures: document FixtureDef's attributes
2022-02-15 14:52:50 +02: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
Ran Benita afe41e5273
Merge pull request #9678 from bluetech/consistent-idval
python: unify code to generate ID from value
2022-02-15 13:23:35 +02:00
eduardo naufel schettino c9cf2d4424
Fix count of selected tests on terminal collection summary (#9628) 2022-02-15 11:17:34 +00:00
Bruno Oliveira 747b8372ea Try to import module before creating dummy modules with 'importmode=importlib'
The dummy modules we introduce in `insert_missing_modules` (due to #7856 and #7859)
would cause problems if the dummy modules actually end up replacing modules
which could be imported normally because they are available in `PYTHONPATH`.

Now we attempt to first import the module via normal mechanisms, and only
introduce the dummy modules if the intermediary modules don't actually exist.

Close #9645
2022-02-14 09:42:05 -03:00
Ran Benita c3aa4647c7 python: unify code to generate ID from value
In the following

    @pytest.mark.parametrize(..., ids=[val])

the ID values are only allowed to be `str`, `float`, `int` or `bool`.

In the following

    @pytest.mark.parametrize(..., [val])

    @pytest.mark.parametrize(..., [pytest.param(..., id=val])

a different code path is used, which also allows `bytes`, `complex`,
`re.Pattern`, `Enum` and anything with a `__name__`.

In the interest of consistency, use the latter code path for all cases.
2022-02-12 19:22:37 +02:00
Bruno Oliveira 8afec9a64d
Add autoflake to pre-commit configuration (#9666) 2022-02-11 14:34:02 -03:00
Bruno Oliveira 3586edc1c9
Merge pull request #9646 from nicoddemus/9643-delay-warning 2022-02-10 14:11:21 -03:00
Bruno Oliveira 88c35123b8 Delay warning about collector/item diamond inheritance
This allows that warning to be filtered by `filterwarnings`.

Fix #9643
2022-02-10 13:50:25 -03:00
Ran Benita 2b6708b892
Merge pull request #9624 from bluetech/unittest-getobj
unittest: restore `UnitTestFunction.obj` to return unbound rather than bound method
2022-02-09 22:43:31 +02:00
Ran Benita 01e1de7a1a Rename ``pythonpath`` plugin to ``python_path``
Fix #9636.
2022-02-09 10:03:20 +02:00
Ran Benita 44290d1f6c
Merge pull request #9609 from kdelee/patch-1
importlib.readers not valid until python 3.10
2022-02-08 15:57:48 +02:00
Anthony Sottile 2442034a1e allow running testids which contain :: in the parametrized portion 2022-02-07 20:19:59 -05:00
Ran Benita d00ca3f8e5 unittest: restore `UnitTestFunction.obj` to return unbound rather than bound method
This fixes #9610.

pytest 7.0.0 (unintentionally) changed `UnitTestFunction.obj`'s' behavior
to match `Function.obj`. That is probably a good thing to have, however
it evidently causes some regressions as described in the issue, so
restore the previous behavior for now. In the future we might want to
make this change again, but with proper consideration.
2022-02-08 00:46:00 +02:00
pre-commit-ci[bot] 2073cce105 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2022-02-08 00:44:52 +02:00
Elijah DeLee d45a19cfde move function specific imports to function
re: review from @asottile that this should only get imported in the function
modify the else/if logic since inside the function we already know the python version is >= 3.10, and just have to know if it is 3.11 or greater
2022-02-08 00:44:52 +02:00
Bruno Oliveira f86a87a315 Update src/_pytest/assertion/rewrite.py
Co-authored-by: Ran Benita <ran@unusedvar.com>
2022-02-08 00:44:52 +02:00
Bruno Oliveira 5f1a2f33da Fix invalid importing of `importlib.reader` in Python 3.9
Fix #9608
2022-02-08 00:44:52 +02:00
Elijah DeLee 15ddccf700 importlib.readers not valid until python 3.10
This exists https://github.com/python/cpython/blob/3.10/Lib/importlib/readers.py and FileReader is in there
This is a 404 https://github.com/python/cpython/blob/3.9/Lib/importlib/readers.py

This change needs to get backported to the 7.0.z branch(s) too
Fixes https://github.com/pytest-dev/pytest/issues/9608
2022-02-08 00:44:52 +02:00
Ran Benita 20c2c30ff2 mark/structures: use class-based NamedTuple syntax
Should hopefully work now in Python>=3.7.
2022-02-05 11:52:36 +02:00
pre-commit-ci[bot] 9d2ffe207b [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2022-01-31 22:20:16 +00:00
Bruno Oliveira f064942f2e
Make 'warnings' and 'deselected' in assert_outcomes optional (#9475)
Fix #9471
2022-01-27 12:18:36 +01:00
Florian Bruhin 396a7def75
Add additional docs for uncooperative ctor deprecation (#9498)
* Add additional docs for uncooperative ctor deprecation

Fixes #9488

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Break up long line

* Recommend kwonly args

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-27 11:49:18 +01:00
Tobias Deiminger b21b008118 Refactor idmaker functions into class IdMaker
This commit only refactors, it does not change or add functionality yet. Public
API is retained. Reason or refactoring:

User provided parameter IDs (e.g. Metafunc.parametrize(ids=...)) had so far
only been used to calculate a unique test ID for each test invocation. That
test ID was a joined string where each parameter contributed some partial ID.

We're soon going to reuse functionality to generate parameter keys for
reorder_items and FixtureDef cache. We will be interested in the partial
IDs, and only if they originate from explicit user information. Refactoring
makes logic and data accessible for reuse, and increases cohesion in general.
2022-01-26 15:42:34 +02:00
Ran Benita acd2034535 fixtures: document FixtureDef's attributes 2022-01-25 23:44:59 +02:00
Ran Benita 52fbf3dbaa fixtures: make code flow clearer
Make the two cases (direct/indirect fixture) clearer. The try-catch
forces the reader to jump around.
2022-01-25 22:44:04 +02:00
Ran Benita 5c69eced6c
Merge pull request #9532 from bluetech/getdir-cache
config: avoid stat storm in _getconftestmodules
2022-01-25 16:21:44 +02:00
Akuli a17e708352
With -vv, display the full skip/xfail reason instead of "..." (#9537)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-25 10:33:22 -03:00
Ran Benita aee04cd49f config: avoid stat storm in _getconftestmodules
Fix #9478.
2022-01-22 00:27:43 +02:00
Ran Benita bb5a4e2d63
Merge pull request #9531 from bluetech/misc
python: fix confused docstring of `Metafunc._resolve_arg_ids`
2022-01-21 17:24:56 +02:00
Ran Benita 471634d6bd python: fix confused docstring of `Metafunc._resolve_arg_ids`
The docstring (and function name itself) described things as if IDs are
being assigned to the argnames, but actually they're assigned to the
parameter sets.
2022-01-21 16:18:44 +02:00
Ran Benita 6d128cd52e python: use a more memory-friendly generator 2022-01-21 14:35:25 +02:00
Ran Benita 74571ba55f Add missing `keywords` type annotations 2022-01-21 14:35:25 +02:00
Ran Benita 456a2538ac python: optimize node keywords initialization
If we do the `update`s in the right order, we can avoid the `mark.name
not in self.keywords` check, since `self.keywords` starts out clean and
`update` will override previously set keywords.
2022-01-21 14:35:25 +02:00
Ran Benita 3c69bc919c python: remove broken/ineffectual keywords marks initialization
By my analysis, this deleted code block has no effect:

1. `self.keywords` is `update`d with `callspec.marks`.
2. `self.own_markers` is `update`d with `callspec.marks`.
3. `self.keywords` is `update`d with `self.own_markers`.

So together steps 2+3 completely undo step 1.
2022-01-21 14:35:24 +02:00
Ran Benita d9bcfa0c2b python: don't redundantly duplicate parent markers to own keywords
This does have a slight semantic change: in a node hierarchy parent ->
child, if parent has a marker applied, then child is constructed, then
`parent.themarker = "overridden"`, previously
`child.keywords['themarker']` would return `True`, now it returns
`"overridden"`. But that's actually what I would have expected so I see
it as more of a bugfix.
2022-01-21 14:34:27 +02:00
Ran Benita 8713c32462 python: unpacked marks need to be added to keywords on all node types
(except `Instance`)

Currently, `Function` does this manually, but other node types don't get
their markers added to their `keywords`, but they should, if only for
consistency.
2022-01-21 14:34:27 +02:00
Ran Benita e9bb1aa233 python: be consistent with what value marks have in keywords
Marks are added to keywords in three places:

- `Node.add_marker`: name -> `Mark`
- `Function.__init__(callspec)`: name -> `Mark`
- `Function.__init__ iter_markers`: name -> True

I think it should be consistent, which will also help with some upcoming
code cleaning. The `Mark` seems more useful than just a `True`, so
switch to that.
2022-01-21 14:34:27 +02:00
Ran Benita 4e5fb520b6 python: remove an unneeded normalize_mark_list call
`callspec.mark` is already `List[Mark]` so no need to normalize it.
2022-01-21 14:34:27 +02:00
Ran Benita 6672a10354 fixtures: use node.ihook instead of open-coding it 2022-01-21 14:29:47 +02:00
Olga Matoula 2ad1b589af
Add docs on pytest.warns(None) deprecation (#9495)
* Add docs on pytest.warns(None) deprecation

* Add new section for common warnings use cases

* Fix references for warnings use cases

* Fix reference link
2022-01-13 18:32:22 +00:00
Ran Benita f1aa7a25de
Merge pull request #9493 from bluetech/conftesting
Some conftest changes
2022-01-12 10:38:14 +02:00
Ran Benita 161bc48117 config: get rid of _conftestpath2mod
It duplicates what PluginManager already knows, and no longer needed now
that symlinks are not resolved (see previous commit).
2022-01-09 12:33:45 +02:00
Ran Benita 0ef882364e config: stop resolving symlinks in conftest paths
This became the wrong thing to do since
322190fd84.
2022-01-09 12:33:45 +02:00
Ran Benita f08a77de77 python: add back `instance` accessor to all python nodes, not just Function
Regressed in 062d91ab4 (pytest 7.0.0rc1 only).

Fix #9486.
2022-01-09 12:14:46 +02:00
Ran Benita d98b695fec config: return Sequence instead of List from _getconftestmodules
Nothing should mutate the internal data structure here.
2022-01-09 00:30:18 +02:00
Ran Benita 0c98f19231 config: make confcutdir check a bit more clear & correct
I think this named function makes the code a bit easier to understand.

Also change the check to explicitly check for "is a sub-path of" instead
of the previous check which only worked assuming that path is within
confcutdir or a direct parent of it.
2022-01-08 22:48:40 +02:00
Ran Benita 1c7644cc7a config: some comments 2022-01-08 22:30:48 +02:00
Ran Benita 5f23157b39 config: remove always truthy condition 2022-01-08 12:36:43 +02:00
Ran Benita b19374bc19 config: fix incorrect cache hit check in _getconftestmodules
This made the cache not work as intended, causing a major slowdown.

See #9478 for discussion and context.

Authored-by: Anthony Sottile <asottile@umich.edu>
2022-01-07 12:47:39 +02:00
Bruno Oliveira 4038752bf3 Ensure Config.inifile is available during pytest_cmdline_main
Fix #9396
2022-01-04 10:03:28 -03:00
Anthony Sottile b0aabe4081 fix mypy 0.930 errors 2021-12-30 06:19:29 -08:00
Hugo van Kemenade 1fd3601caa Drop support for EOL Python 3.6 2021-12-30 12:37:18 +02:00
Ran Benita b9663fed6f
Merge pull request #9442 from hramezani/drop_python_36
Drop Python3.6 in CI, setup.cfg, and readme.
2021-12-30 12:22:13 +02:00
Hasan Ramezani b72ad0fa8e Remove has_flags conditions from src._pytest.assertion.rewrite._read_pyc 2021-12-28 10:11:45 +01:00
Hasan Ramezani 400915067f Move nullcontext import to src._pytest.logging. 2021-12-28 10:11:45 +01:00
Hasan Ramezani 3d7cd77017
Update syntax to Python3.7+. 2021-12-28 10:11:35 +01:00
Ran Benita 69da199f6e
Merge pull request #9438 from bluetech/pytest-legacypath-imports
pytest: bring back direct imports of TempdirFactory, Testdir
2021-12-27 15:03:05 +02:00
Ran Benita fcef7e49fd
Merge pull request #9447 from bluetech/code-cut-pathlike
code: accept any `os.PathLike[str]` in `Traceback.cut`
2021-12-27 15:02:20 +02:00
Kian Meng, Ang 55debfad1f
Fix typos (#9424) 2021-12-27 09:23:15 -03:00
Ran Benita 0da4760715 code: accept any `os.PathLike[str]` in `Traceback.cut`
Before 7.0.0rc1, the function accepted `Union[str, py.path.local]`, and
`py.path.local` compares equal to the string path, so a user was able to
pass the path as a string and it would work. In 7.0.0rc1 we changed the
`py.path.local` to `Path` which doesn't compare equal to the string
path, which breaks compatibility (e.g. the `sybil` package).

This restores compatibility for this function by accepting any
`os.PathLike[str]` and only comparing the string representations.
2021-12-27 11:26:32 +02:00
Ran Benita 7fc2cf51c2
Merge pull request #9441 from bluetech/nose-setup-callable
python: skip nose setup/teardown fixtures if non-callable
2021-12-27 11:09:51 +02:00
Ran Benita 3128080806 pytest: bring back direct imports of TempdirFactory, Testdir
The monkeypatch approach doesn't work for `import pytest;
pytest.TempdirFactory`.

Fix #9432.
2021-12-25 13:27:02 +02:00
Ran Benita 10e21dadee python: skip nose setup/teardown fixtures if non-callable
Since commit 89f0b5b5a2 cases as in the
added test started to fail, like they do for the standard pytest names
(`setup_module` etc). But the name `setup` in particular is way too
common for us to start taking it over more aggressively, so restore the
previous behavior which required the object to be callable.

Fix #9391.
2021-12-25 12:09:11 +02:00
Anthony Sottile c69b84f236 fix typing issues in mypy 0.920 2021-12-21 20:42:32 -05:00
Yuval Shimon 3bbadda0cf
Merge pull request #9407 from yuvalshi0/remove-eq-format
Avoid specialized assert formatting when we detect that __eq__ is overridden
2021-12-14 10:53:56 +02:00
Ran Benita 0e69c62ece doc: add a `hook` crossref type
Allow writing

    🪝`pytest_cmdline_main`

instead of

    :func:`pytest_cmdline_main <_pytest.hookspec.pytest_cmdline_main>`
2021-12-12 16:29:30 +02:00
Yuval Shimon 7cf2b51d8e
Merge branch 'pytest-dev:main' into remove-eq-format 2021-12-12 15:16:58 +02:00
Yuval Shimon 2d7905b13b support pypy 2021-12-12 15:14:24 +02:00
Yuval Shimon df74e5c532 fixing pre-commit 2021-12-12 14:53:29 +02:00
pre-commit-ci[bot] 9166ff6cb5 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2021-12-12 12:49:24 +00:00
Yuval Shimon 8c3b17263b removing unnecessary changes 2021-12-12 14:47:00 +02:00
Yuval Shimon a67c547536 fixing tests 2021-12-12 14:45:47 +02:00
Yuval Shimon 31f42ef83f small fix 2021-12-12 14:40:46 +02:00
Yuval Shimon 897395afd5 fix 9326 2021-12-12 14:38:45 +02:00
Ran Benita dd609e150b
Merge pull request #9264 from bluetech/no-pycollector
Make PyCollector an implementation detail - don't use in hook type annotation
2021-12-11 22:57:49 +02:00
Ran Benita c7be96dae4
Merge pull request #9392 from bluetech/rm-7-deprecated
Remove deprecations scheduled for removal in pytest 7.1
2021-12-08 22:59:42 +02:00
Ran Benita ee93557ef3 Remove `PytestRemovedIn7Warning`
Fix #8838.
2021-12-08 15:58:08 +02:00
Ran Benita e05e696fda Make PyCollector an implementation detail - don't use in hook type annotation
The `pytest_pycollector_makeitem` argument `collector` is currently
annotated with type `PyCollector`. As part of #7469, that would have
required us to expose it in the public API. But really it's an
implementation detail, not something we want to expose. So replace the
annotation with the concrete python collector types that are passed.

Strictly speaking, `pytest_pycollector_makeitem` is called from
`PyCollector.collect()`, so the new type annotation is incorrect if
another type subclasses `PyCollector`. But the set of python collectors
is closed (mapping to language constructs), and the type is private, so
there shouldn't be any other deriving classes, and we can consider it
effectively sealed (unfortunately Python does not provide a way to
express this - yet?).
2021-12-08 15:20:23 +02:00
Bruno Oliveira 3ba9c01f9b
Hide internal stack when using pytest.approx() in bool context (#9394)
This makes the error traceback point directly to the offending usage, rather
than to the internal `Approx.__bool__` method.
2021-12-08 10:46:44 +01:00
Ran Benita 0f39f11d88 Remove deprecated `pytest.collect` module 2021-12-07 22:27:35 +02:00
Ran Benita 4a45a5e983 Remove deprecated `-k foobar:` syntax 2021-12-07 22:27:35 +02:00
Ran Benita 927d9d274f Remove deprecated `-k -foobar` syntax 2021-12-07 22:27:35 +02:00
Ran Benita 41d8fb09ca Remove deprecated `pytest_warning_captured` hook 2021-12-07 22:27:35 +02:00
Ran Benita 0b0e2d2dbb Remove deprecated `_fillfuncargs` function 2021-12-07 22:27:35 +02:00
Yuval Shimon dc7091502d
Fixed error message prints function decorators when using assert in Python 3.9 and above. (#9359) 2021-12-07 11:31:03 +02:00
pre-commit-ci[bot] dd53cc7e38 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2021-12-06 21:12:33 +00:00
Bruno Oliveira 70d3d0f390
Drop readline workaround introduced in #1281 (#8848)
Fix #8733
Closes #8847
2021-12-06 19:50:11 +01:00
Florian Bruhin 663be09723
Improve reference and path/fspath docs (#9341)
* Improve reference and path/fspath docs

Closes #9283

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixups

* Add explanation

* Update wording after #9363

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-12-06 11:25:05 +01:00
Bruno Oliveira a335ade1f5
Rename pathlib hook parameters (#9363)
* Rename pytest_ignore_collect fspath parameter to collection_path

* Rename pytest_collect_file fspath parameter to file_path

* Rename pytest_pycollect_makemodule fspath parameter to module_path

* Rename pytest_report_header startpath parameter to start_path

* Rename pytest_report_collectionfinish startpath parameter to start_path

* Update docs with the renamed parameters

* Use pytest-flakes fork temporarily to prove it works

* Use pytest-flakes 4.0.5
2021-12-03 13:14:09 +01:00
GergelyKalmar 1bcc2f87a2 Do not display empty worker info 2021-11-30 18:59:46 +01:00
Ran Benita a172a4141b Change PytestRemovedIn7Warning to error by default
Per our backward compatibility policy.

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2021-11-14 23:57:10 +02:00
Ran Benita 128f29ee35 Categorize deprecation warnings to `PytestRemovedInXWarning`
Closes #7480.

This allows us to more easily follow our deprecation policy of turning
warnings into errors for the X.0 releases before complete removal in
X.1.

It also makes the deprecation timeline clear to both the users and
pytest developers -- it can be hard to keep track.

Note that the designation is not meant to be a binding contract - if the
time comes for removal of a specific deprecation but we decide it's too
soon, can just bump it to the next major.

Inspired by Django:
https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/submitting-patches/#deprecating-a-feature
2021-11-14 23:57:10 +02:00
Ran Benita 062d91ab47
python: remove the `Instance` collector node 2021-11-13 14:03:44 +02:00
Florian Bruhin 5d87a27434
Elide pytest-internal paths for --fixtures (#9281)
* Elide pytest-internal paths for --fixtures

Fixes #8822

* Make flake8 happy
2021-11-10 15:16:41 +01:00
Ran Benita 63899c76a4 legacypath: support late-loading of pytester plugin
Fixes #9280.

Previous approach didn't support pytester being loaded using
`pytest_plugins = "pytester"` in a conftest.
2021-11-08 21:56:40 +02:00
Ran Benita f87df9c52e
nodes: keep plugins which subclass Item, File working for a bit more (#9279)
* nodes: keep plugins which subclass Item, File working for a bit more

Fix #8435.

* Update src/_pytest/nodes.py

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

Co-authored-by: Florian Bruhin <me@the-compiler.org>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2021-11-08 14:51:04 +00:00
Simon K eb6c4493b2
Deprecation of `msg=` for both `pytest.skip()` and `pytest.fail()`. (#8950)
* porting pytest.skip() to use reason=, adding tests

* avoid adding **kwargs, it breaks other functionality, use optional msg= instead

* deprecation of `pytest.fail(msg=...)`

* fix bug with not capturing the returned reason value

* pass reason= in acceptance async tests instead of msg=

* finalising deprecations of `msg` in `pytest.skip()` and `pytest.fail()`

* Update doc/en/deprecations.rst

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

* Update doc/en/deprecations.rst

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

* fix failing test after upstream merge

* adding deprecation to `pytest.exit(msg=...)`

* add docs for pytest.exit deprecations

* finalising deprecation of msg for pytest.skip, pytest.exit and pytest.fail

* hold a reference to the Scope instance to please mypy

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2021-11-08 15:31:14 +01:00
Thomas Hisch 59373fe402
Merge pull request #9271 from thisch/unpack
Inline PercentStyleMultiline._update_message
2021-11-08 12:54:44 +01:00
Ran Benita 86446edc86
Merge pull request #9273 from bluetech/nose-fixtures2
nose: fix class- and module-level fixture behavior
2021-11-07 23:14:39 +02:00
Simon K 7037a58711
use list comp for getreports in terminal py (#9243) 2021-11-06 16:32:37 +00:00
Ran Benita 89f0b5b5a2 nose: fix class- and module-level fixture behavior
Fixes #9272.

Fixing the issue directly in the plugin is somewhat hard, so do it in
core. Since the plugin is going to be deprecated, I figure it's OK to
cheat a bit.
2021-11-06 14:45:24 +02:00
Oleg Höfling 49f934618c
Replace hardcoded links to Github issues with extlinks (#9234) 2021-11-06 11:16:11 +02:00
Thomas Hisch d8b647970f Inline PercentStyleMultiline._update_message
and take advantage of dict unpacking operator.
2021-11-05 23:08:30 +01:00
Ran Benita b0aa870b11 Export CollectReport and TestReport
Refs #7469.
2021-11-02 20:58:51 +02:00
Ran Benita a53abe93d8
Merge pull request #9208 from bluetech/legacypath-plugin
Add legacypath plugin, move py.path stuff there
2021-11-02 20:35:12 +02:00
Harshna 9d17cebe64
Use correct input arg type for _bestrelpath (#9238)
Closes #8990
2021-11-01 17:43:05 +02:00
denivyruck 0191563fd6
DoctTest line numbers not found due to method wrapping (#8861)
Closes #8796
2021-11-01 09:01:25 +02:00
Alexander King 31c207a0b5
Support forwardslash characters in identifiers (#9249)
Closes #8377.
2021-11-01 08:54:18 +02:00
Ran Benita e6eac28f0e legacypath: only add `testdir` and `tmpdir` fixtures if corresponding plugins are registered
This preserves the existing behavior and gives a proper error message
in case e.g. `testdir` is requested without the `pytester` plugin being
loaded.
2021-10-29 13:11:12 +03:00
Ran Benita c3dff755af Move Node.fspath to legacypath plugin 2021-10-28 21:51:51 +03:00
Ran Benita ce7cff9f8e Move pathlist support to legacypath plugin 2021-10-28 21:51:51 +03:00