Commit Graph

728 Commits

Author SHA1 Message Date
Jay ca40380e99
Add check for zero denominator in approx (#10624)
Closes #10533
2023-01-24 07:07:42 -03:00
q0w bd7919e03d
Initialize args and args_source during Config.__init__
Closes #10626

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2023-01-21 08:19:54 -03:00
Ran Benita 310b67b227
Drop attrs dependency, use dataclasses instead (#10669)
Since pytest now requires Python>=3.7, we can use the stdlib attrs
clone, dataclasses, instead of the OG package.

attrs is still somewhat nicer than dataclasses and has some extra
functionality, but for pytest usage there's not really a justification
IMO to impose the extra dependency on users when a standard alternative
exists.
2023-01-20 11:13:36 +02:00
Marko Pacak 9fbd67dd4b
Class methods can now be discovered as tests (#10552)
Fix #10525
2022-12-02 15:53:04 +00:00
Anthony Sottile 1b47de7d7f update does_not_raise docs now that pytest is 3.7+ only 2022-06-29 13:13:15 -04:00
Zach OBrien 96412d19ab
Fix representation of tuples in approx
Closes #9917
2022-06-14 06:54:32 -03:00
Zac Hatfield-Dodds 29462b1277 type-ignore in error-message test 2022-05-10 23:24:13 -07: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
Babak Keyvani 3444d35c54 improve `pytest.raises` 2022-04-30 17:56:36 -06: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
Bruno Oliveira 5f3d94c47e
Disallow unordered sequences in pytest.approx (#9709)
Fix #9692
2022-02-24 10:16:35 -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
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
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
Hugo van Kemenade 61417b2551 Drop support for EOL Python 3.6 2021-12-30 13:25:34 +02:00
Ran Benita 0b0e2d2dbb Remove deprecated `_fillfuncargs` function 2021-12-07 22:27:35 +02: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
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 7c0011374c Move FixtureRequest.fspath to legacypath plugin 2021-10-28 21:51:51 +03:00
Ran Benita 259cff59f5 Remove {pytester,testdir}.Session aliases
This causes `Session` documentation to be rendered again in full under
`pytester` and `testdir` in the API Reference. I tried but couldn't get
sphinx to hide it.

Since it's a pretty odd thing to have (should just use
`pytest.Session`), and I couldn't find any plugin which uses this, let's
just remove it.
2021-10-23 10:25:29 +03:00
Ran Benita 7eee5c1634 Change `Node.reportinfo()` return value from `py.path` to `str|os.PathLike[str]`
`reportinfo()` is the last remaining py.path-only code path in pytest,
i.e. the last piece holding back py.path deprecation. The problem with
it is that plugins/users use it from both sides -- implementing it
(returning the value) and using it (using the return value). Dealing
with implementers is easy enough -- allow to return `os.PathLike[str]`.
But for callers who expect strictly `py.path` this will break and
there's not really a good way to provide backward compat for this.

From analyzing a corpus of 680 pytest plugins, the vast majority of
`reportinfo` appearances are implementations, and the few callers don't
actually access the path part of the return tuple.

As for test suites that might access `reportinfo` (e.g. using
`request.node.reportinfo()` or other ways), that is much harder to
survey, but from the ones I searched, I only found case
(`pytest_teamcity`, but even then it uses `str(fspath)` so is unlikely
to be affected in practice). They are better served with using
`node.location` or `node.path` directly.

Therefore, just break it and change the return type to
`str|os.PathLike[str]`.

Refs #7259.
2021-10-09 15:02:03 +03:00
Ran Benita 5fc3e35afb
Merge pull request #9144 from bluetech/py36_order_by_definition
py36+ tests are definition ordered [v2]
2021-10-01 16:17:37 +03:00
Florian Bruhin 112204cf8d
Fix non-sensical error message (#9077)
* Fix non-sensical error message

Introduced in 12de92cd2b / #7698

* Add a test

* Put the unit back into unittest

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

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

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-09-24 06:15:53 +02:00
Kale Kundert af42e7154a
Prevent approx from being used without a comparison (#9061)
Some of the top search-engine hits for pytest.approx use the function without actually comparing it to anything.

This PR will cause these tests to fail by implementing approx.__bool__() to raise an AssertionError that briefly explains how to correctly use approx.
2021-08-30 18:19:31 +00:00
Bruno Oliveira a83b359cf0
Refactor internal scope handling by introducing Scope enum
PR #8913
2021-08-01 06:11:56 -03:00
Bruno Oliveira 2c4c57e135 Revert fspath deprecation
It is not clear yet how we should proceed with this deprecation
because `pytest.Item.reportinfo` is public API and returns a `py.path` object,
and is not clear how plugins and our examples should handle that.

Reverting just the deprecation aspect of #8251 so we can get a 7.0.0 release out.

We will reintroduce the deprecation later once we have a clear path moving forward with replacing `reportinfo`.

Closes #8445
Closes #8821
2021-07-13 08:24:39 -03:00
Graeme Smecher 5c04674e96 Generate useful parameterization IDs for complex() numbers. 2021-07-12 12:27:24 -07:00
Miro Hrončok 5165bf97c6
Revert "Adjust enum reprs for Python 3.10" (#8896)
This reverts commit 710446420c.

The change was reverted in Python 3.10.0b4:

https://mail.python.org/archives/list/python-dev@python.org/message/LSTMFAPSPD3BGZ4D6HQFODXZVB3PLYKF/
2021-07-12 14:32:27 +00:00
Rahul Kumaresan c516dba69a
add feature to view fixture source location in invocations with --fixtures-per-test option (#8626)
* add feature to view fixture source location in invocations with --fixtures-per-test option

* remove unrelated changes to show_fixtures_per_test::test_doctest_items

* eshew the extraneous else in _show_fixtures_per_test.write_fixture

* enable the accommodation of multi-line docstring with --fixtures-per-test option

* add feature to view fixture source location in invocations with --fixtures

* add colour encoding to fixture location paths

* add changelog for #8606 fixing

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

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

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-05-14 14:38:55 +02:00
Florian Bruhin e354c5c919 Fix warning filters used in tests 2021-05-04 17:25:02 +02:00
Florian Bruhin 710446420c Adjust enum reprs for Python 3.10
Potential fix for #8546
2021-05-04 17:24:50 +02:00
Tarcísio Fischer 9d9b84d175
Improve pytest.approx error messages readability (Pull request) (#8429)
Improve pytest.approx error messages readability (Pull request)
2021-04-30 07:36:56 -03:00
Miroslav Šedivý fbe66244b8
Fix some typos, remove redundant words and escapes (#8564)
* doc: Fix typos, remove double words

* Remove redundant escapes in regex
2021-04-19 20:39:08 +00:00
pre-commit-ci[bot] d200598de9
[pre-commit.ci] pre-commit autoupdate (#8547)
* [pre-commit.ci] pre-commit autoupdate

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

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

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ran Benita <ran@unusedvar.com>
2021-04-14 12:49:09 +03:00
Tadeu Manoel b706a2c048
Fix error with --import-mode=importlib and modules containing dataclasses or pickle (#7870)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

Fixes #7856, fixes #7859
2021-04-05 17:10:03 -03:00
Ran Benita e515264eb1 Remove yet more unnecessary py.path uses 2021-03-18 10:23:48 +02:00
Ran Benita fe215bda6b
Merge pull request #8446 from bluetech/unnecessary-py-path-2
More py.path removal work
2021-03-18 10:20:59 +02:00
Kale Kundert dd3709718d
Merge pull request #8453 from encukou/rel-error-message
Fix value in error message about negative relative tolerance
2021-03-16 16:43:31 -04:00
pre-commit-ci[bot] da4abd1c82 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2021-03-16 19:10:55 +00:00
Petr Viktorin 43b451e95e Add tests for the error message 2021-03-16 20:09:17 +01:00
Ran Benita f0c7043138 Remove/replace some more unnecessary uses of py.path 2021-03-15 10:39:44 +02:00
Ran Benita 59251e8a2a Remove/replace some unneeded usages of py.path 2021-03-14 14:12:28 +02:00
Pierre Mourlanne af9f27a874
Approx decimal sequence mapping (#8422) 2021-03-13 16:01:23 +02:00
Ronny Pfannschmidt 22dad53a24 implement Node.path as pathlib.Path
* reorganize lastfailed node sort

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2021-03-06 21:32:03 +01:00
Matthew Hughes c9bb4c418f fixup! Rename variables 'tmpdir'->'tmp_path'
* Add some more of these
* Also reintroduce+rename instances of fixture usages that were
'tmpdir'->'tmp_path'
2021-02-21 13:10:07 +00:00
Matthew Hughes 0e5e4e03e6 Remove some unused 'tmpdir's 2021-02-20 18:01:42 +00:00
Ran Benita f42b68ccaa runner: rename SetupState.prepare -> setup
This is the usual terminology we use, and matches better with
`teardown_exact()` and `pytest_runtest_setup()`.
2021-02-06 20:46:08 +02:00
Ran Benita 637300d13d testing: fix some tests to be more realistic
Perform the operations in the order and context in which they can
legally occur.
2021-01-24 14:08:39 +02:00