* Added title to draw attention to the easily-missed information on non-numeric types for approx.
* Changed spelling of all cases of "nonnumeric" to "non-numeric" within docstrings for clarity and consistency with .rst files.
Related to #13218
* raisesgroup followups
* renames src/_pytest/raises_group.py to src/_pytest/raises.py
* moves pytest.raises from src/_pytest/python_api.py to src/_pytest/raises.py
* adds several newsfragments that should've been bundled with #13192
* add more detailed error message if you try to do RaisesGroup((ValueError, TypeError))
* mess around with ValueError vs TypeError on invalid expected exception
* revert change in behaviour if raises has a type mismatch
* add check example to raises, fix test after behaviour revert
* made args to AbstractMatcher, RaisesExc and RaisesGroup pos/kw-only
---------
Co-authored-by: Ran Benita <ran@unusedvar.com>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* chore: setuponly - migrate to f string
* chore: MockTiming - move impl to _pytest.timing
* chore: fixture tests: migrate to f-strings
* chore: skipping tests: migrate to f-strings
* chore: junitxml tests: add more type annotations
* chore: junitxml tests: introduce more typesafe helpers
* add changelog
* test junitxml: split the DomNode type to express the Document/Element difference
* fixup: undo accidential name-mangling in the junitxml test helpers
* fixup: junitxml logging test - restore validation for expected output nodes
* fixup: have fake config .getini use correct types
* Update changelog/12017.improvement.rst
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
* use contrib category for changelog
* use datetime.fromisoformat instead of strptime
* post rebase ruff fixes
* add extra coverage for junit test helpers
---------
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
* Prevent parametrize with scope from breaking fixture dependencies
* Add myself to AUTHORS
* Fix the regression test
* Assert fixture value inside the test
---------
Co-authored-by: Bruno Oliveira <bruno@pytest.org>
During the sprint we discussed fixing the above issue and thought maybe it's a better idea to add a better representation to fixtures. To do this without patching the object more, this PR refactors fixtures to have a class with attributes.
The main rational behind that is:
- Now we have a type for fixtures makes it easier to check for fixture types and no need to perform cast on objects. Removed monkey patching.
- They are no longer functions that carry a class within them.
- When you decorate a function with a fixture it's not possible to call it anymore. So it makes more sense for it to not be a function or method.
Fixes#11525
---------
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Ran Benita <ran@unusedvar.com>
Previously `approx` would show an internal error when passed a collection with numbers and non-numbers mixed:
```
E (pytest_assertion plugin: representation of details failed: /tmp/test_a/.venv/lib/python3.12/site-packages/_pytest/python_api.py:343: TypeError: unsupported operand type(s) for -: 'str' and 'str'.
E Probably an object has a faulty __repr__.)
```
The problem was that it was unconditionally computing the diff for every element.
This change introduces a try/except catch around the code related to computing the diff, and ignores it instead of letting the error be raised.
Fixes#13010
Co-authored-by: Bruno Oliveira <bruno@pytest.org>
In #11220, an unintended change in reordering was introduced by changing the way indices were assigned to direct params. This PR reverts that change and reduces #11220 changes to just refactors.
After this PR we could safely decide on the solutions discussed in #12008, i.e. #12082 or the one initially introduced in #11220 .
Fixes#12008
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Adjust `ApproxScalar.__repr__` to format tolerances in decimal form for smaller ranges.
Closes#6985
---------
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
The fix for Issue #6541 caused regression where cache hits became cache misses, unexpectedly.
Fixes#6962
---------
Co-authored-by: Nicolas Simonds <nisimond@cisco.com>
Co-authored-by: Bruno Oliveira <bruno@pytest.org>
Co-authored-by: Ran Benita <ran@unusedvar.com>
Fix#12355.
In the issue, it was reported that the `reorder_items` has quadratic (or
worse...) behavior with certain simple parametrizations. After some
debugging I found that the problem happens because the "Fix
items_by_argkey order" loop keeps adding the same item to the deque,
and it reaches epic sizes which causes the slowdown.
I don't claim to understand how the `reorder_items` algorithm works, but
if as far as I understand, if an item already exists in the deque, the
correct thing to do is to move it to the front. Since a deque doesn't
have such an (efficient) operation, this switches to `OrderedDict` which
can efficiently append from both sides, deduplicate and move to front.
The `.parent` was incorrectly removed in
a21fb87a90, but it was actually correct
(well, it assumes that Module.path.parent == Package.path, which I'm not
sure is always correct, but that's a different matter). Restore it.
Fix#12328.
* added test case in testing/python/approx.py based on test case provided by reporter in issue #12114
* test cases pass for pytest testing/python/approx.py
* expanded the type annotation to include objects which may cast to a array and renamed other_side to other_side_as_array and asserted that it is not none
and also fixes a regression in pytest 8.0.0 where `setup_method` crashes
if the class has static or class method tests.
It is allowed to have a test class with static/class methods which
request non-static/class method fixtures (including `setup_method`
xunit-fixture). I take it as a given that we need to support this
somewhat odd scenario (stdlib unittest also supports it).
This raises a question -- when a staticmethod test requests a bound
fixture, what is that fixture's `self`?
stdlib unittest says - a fresh instance for the test.
Previously, pytest said - some instance that is shared by all
static/class methods. This is definitely broken since it breaks test
isolation.
Change pytest to behave like stdlib unittest here.
In practice, this means stopping to rely on `self.obj.__self__` to get
to the instance from the test function's binding. This doesn't work
because staticmethods are not bound to anything.
Instead, keep the instance explicitly and use that.
BTW, I think this will allow us to change `Class`'s fixture collection
(`parsefactories`) to happen on the class itself instead of a class
instance, allowing us to avoid one class instantiation. But needs more
work.
Fixes#12065.
- Separate the requesting from the requested.
- Avoid the term "factory", I think most people don't distinguish
between "fixture" and "fixture function" (i.e. "factory") and would
find the term "factory" unfamiliar.