Commit Graph

3325 Commits

Author SHA1 Message Date
Yutian Li 5af46f3d4e
Fix crashing under squashfuse_ll read-only mounts (#12301)
Fixes #12300
2024-05-09 15:04:58 -03:00
Brian Okken 8efbefb2d7
New --xfail-tb flag (#12280)
Fix #12231
2024-05-07 14:37:00 -03:00
Bruno Oliveira 84e59af8c8
Document exceptions raised by exit, skip, xfail, fail, and importorskip (#12285)
As commented on: https://github.com/pytest-dev/pytest/issues/7469#issuecomment-2094104215
2024-05-05 22:53:16 +00:00
Anita Hammer 97610067ac
Handle KeyboardInterrupt and SystemExit at collection time (#12191) 2024-05-02 11:59:09 +00:00
Ben Brown 4c5298c395
Add back "Fix teardown error reporting when --maxfail=1 (#11721)" (#12279)
Closes #11706.

Originally fixed in #11721, but then reverted in #12022 due to a regression in pytest-xdist.

The regression was fixed on the pytest-xdist side in pytest-dev/pytest-xdist#1026.
2024-05-02 10:42:31 +03:00
Pierre Sassoulas 2b6c946a2b [mypy 1.10.0] Remove 'type: ignore' that became useless 2024-04-30 18:11:06 +02:00
Pierre Sassoulas 4788165e69 [ruff UP031] Fix to use format specifiers instead of percent format 2024-04-30 18:06:26 +02:00
Ran Benita feaae2fb35
Merge pull request #12264 from bluetech/reraise-with-original-tb
fixtures,runner: fix tracebacks getting longer and longer
2024-04-29 20:02:44 +03:00
Ran Benita e847b2a5a9 pre-commit: replace `debug-statements` hook with ruff
Ruff supports this functionality so we can use it.
2024-04-28 17:06:07 +03:00
Ran Benita ebc4540436
Merge pull request #12258 from bluetech/xdist-align
terminal: fix progress percentages not aligning correctly in xdist
2024-04-28 16:52:40 +03:00
Ran Benita 3e81cb2f45 runner: fix tracebacks for failed collectors getting longer and longer
Refs https://github.com/pytest-dev/pytest/issues/12204#issuecomment-2081239376
2024-04-28 13:30:05 +03:00
Ran Benita 0b91d5e3e8 fixtures: fix tracebacks for higher-scoped failed fixtures getting longer and longer
Fix #12204.
2024-04-28 13:06:32 +03:00
Ran Benita 50d1e81713 terminal: fix progress percentages not aligning correctly in xdist
Fix #7166
2024-04-28 11:33:18 +03:00
Ran Benita 1a84d233f3 terminal: some minor code cleanups
No logical changed intended.
2024-04-28 11:33:18 +03:00
Ran Benita 127a372928
Merge pull request #12259 from bluetech/plain-raise
runner: avoid adding uninteresting entry to tracebacks
2024-04-28 11:21:15 +03:00
Ran Benita fc5c960304 runner: avoid adding uninteresting entry to tracebacks
In these two cases which re-raise an immediately-caught exception, do
the re-raising with `raise` instead of `raise exc`, because the `raise
exc` adds an uninteresting entry to the exception's traceback (that of
itself), while `raise` doesn't.
2024-04-28 01:42:43 +03:00
Bruno Oliveira 835765c9d3
Merge pull request #12130 from bluetech/fixtures-inline
fixtures: inline some functions to streamline the code
2024-04-27 10:01:36 -03:00
Daniel Miller 7e7503c0b0
unittest: report class cleanup exceptions (#12250)
Fixes #11728

---------

Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
2024-04-27 09:49:05 -03:00
Ran Benita 882c4da2f3 fixtures: inline `fail_fixturefunc`
Doesn't add much.
2024-04-27 09:48:14 -03:00
Ran Benita 2e8fb9f140 fixtures: extract a `_check_fixturedef` method
This stuff is less interesting when reading `_get_active_fixturedef`.
2024-04-27 09:48:14 -03:00
Ran Benita acf2971f46 fixtures: inline `_getnextfixturedef` into `_get_active_fixturedef` 2024-04-27 09:48:14 -03:00
Ran Benita 3c77aec1da fixtures: move "request" check early 2024-04-27 09:48:14 -03:00
Ran Benita d217d68cde fixtures: inline `_compute_fixture_value` 2024-04-27 09:48:14 -03:00
Ran Benita 530be28575 fixtures: use early return in `_get_active_fixturedef` 2024-04-27 09:48:14 -03:00
Ran Benita 80ca255d42 pathlib: make `absolutepath` support `os.PathLike[str]`
This slightly simplifies a bit of path.
2024-04-27 11:53:01 +03:00
Ran Benita 1a332802ff Avoid slicing `sys.version_info` in version conditionals
It is unnecessary, and some static analyzers don't handle it.
2024-04-27 01:14:21 +03:00
Shekhar verma 4eb8b6d525
Changed importError to ModuleNotFoundError (#12220)
* Changed importError to ModuleNotFoundError

* added testing for importorskip

* added exc_types parameter in importorskip

* Added warning and Test Cases

* Improve tests and docs

* Improve deprecation docs

* Change exc_type to kw only

* Apply suggestions from code review

Co-authored-by: Florian Bruhin <me@the-compiler.org>

* Fix check

---------

Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Florian Bruhin <me@the-compiler.org>
2024-04-26 09:48:57 +02:00
poulami-sau 5cffef7f07
Fixed Bug Regarding Attribute Error in pytest.approx For Types Implicitly Convertible to Numpy Arrays (#12232)
* 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
2024-04-23 10:45:33 +02:00
Ran Benita 58136c5376 hookspec: deprecate hookimpls requesting py.path parameters 2024-04-21 11:37:56 +03:00
Bruno Oliveira 042625957a
Fully type annotate pathlib.py (#12229)
Add full type annotations to `pathlib.py` and remove the `allow-untyped-defs` directive.
2024-04-20 16:32:36 -03:00
Bruno Oliveira 6fb474a3eb
Refactor insert_missing_modules function (#12210)
Makes the logic more straightforward IMO.
2024-04-20 11:58:14 +00:00
Bruno Oliveira ff806b239e
importlib: set children as attribute of parent modules (#12208)
Now `importlib` mode will correctly set the imported modules as an attribute of their parent modules.

As helpfully posted on #12194, that's how the Python import module works so we should follow suit.

In addition, we also try to import the parent modules as part of the process of importing a child module, again mirroring how Python importing works.

Fix #12194
2024-04-20 11:31:33 +00:00
dj 48b6d18834
Add PYTEST_VERSION environment variable (#12190)
Among other things, it can be used to check if a code is running from within a pytest session.

Fixes #9502
2024-04-18 07:45:47 -03:00
HolyMagician03-UMich 089116bdff
short test summary: do not truncate text when -vv is given
Fix #11777

---------

Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
2024-04-10 08:07:18 -03:00
Bruno Oliveira 99890636bf
Refine how we detect namespace packages (#12169)
Previously we used a hand crafted approach to detect namespace packages, however we should rely on ``importlib`` to detect them for us.

Fix #12112

---------

Co-authored-by: Ran Benita <ran@unusedvar.com>
2024-04-09 13:21:51 -03:00
Ran Benita 5acc3f86ac
Merge pull request #12168 from tamird/fix-gitignore-missing
Initialize cache directory in isolation
2024-04-06 23:18:19 +03:00
Tamir Duberstein 2e65f4e3ac
Initialize cache directory in isolation
Creating and initializing the cache directory is interruptible; this
avoids a pathological case where interrupting a cache write can cause
the cache directory to never be properly initialized with its supporting
files.

Unify `Cache.mkdir` with `Cache.set` while I'm here so the former also
properly initializes the cache directory.

Closes #12167.
2024-04-03 16:26:43 +01:00
Ran Benita 1188ea2608 Move show-fixtures code from python.py to fixtures.py
It makes more sense, also, we have a long term idea of generalizing
fixture support to items defined by other plugins, not just python, in
which case `--fixtures` would definitely not be python-plugin
specific.
2024-04-02 23:02:10 +03:00
Pierre Sassoulas 1125296b53 Small performance/readability improvments when iterating dictionnary with ``keys()``
Based on pylint's message ``consider-iterating-dictionary`` suggestion.
Surprisingly using a dict or set comprehension instead of a new temp var is
actually consistently slower here, which was not intuitive for me.

```python
from timeit import timeit

families = {1: {"testcase": [1, 2, 3, 5, 8]}}
attrs = {1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h"}

class Old:
    def old(self):
        self.attrs = attrs
        temp_attrs = {}
        for key in self.attrs.keys():
            if key in families[1]["testcase"]:
                temp_attrs[key] = self.attrs[key]
        self.attrs = temp_attrs

class OldBis:
    def old(self):
        self.attrs = attrs
        temp_attrs = {}
        for key in self.attrs:
            if key in families[1]["testcase"]:
                temp_attrs[key] = self.attrs[key]
        self.attrs = temp_attrs

class New:
    def new(self):
        self.attrs = attrs
        self.attrs = { # Even worse with k: v for k in self.attrs.items()
            k: self.attrs[k] for k in self.attrs if k in families[1]["testcase"]
        }

if __name__ == "__main__":
    n = 1000000
    print(f"Old: {timeit(Old().old, number=n)}")
    print(f"Just removing the keys(): {timeit(OldBis().old, number=n)}")
    print(f"List comp, no temp var: {timeit(New().new, number=n)}")
```

Result:
Old: 0.9493889989680611
Just removing the keys(): 0.9042672360083088
List comp, no temp var: 0.9916125109884888

It's also true for the other example with similar benchmark, but the exact
code probably does not need to be in the commit message.
2024-03-31 14:43:07 +02:00
John Litborn e64efd8653
Don't reregister subfixture finalizer in requested fixture if value is cached (#12136) 2024-03-31 15:02:09 +03:00
Ran Benita 3eb16b34be fixtures: stop using `request.param_index` in fixture cache key
When `param` is not defined, `param_index` is always 0 (see
`_compute_fixture_value`), so no point in using it besides adding some
confusion.
2024-03-23 12:07:24 +02:00
Sebastian Meyer e7bf216516
doc: add versionadded to `ExceptionInfo.group_contains` (#12141) 2024-03-19 19:54:26 -03:00
John Litborn 70c11582aa
Don't add fixture finalizer if the value is cached (#11833)
Fixes #1489
2024-03-16 23:45:56 +02:00
pre-commit-ci[bot] c0532dda18
[pre-commit.ci] pre-commit autoupdate (#12115)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Ran Benita <ran@unusedvar.com>
2024-03-13 15:30:18 +02:00
Ran Benita 7eaaf370bb
doc: add versionadded to `Stash` and `StashKey`
Fixes #12107
2024-03-11 18:22:16 +02:00
Ran Benita 0dc0360351 python: fix instance handling in static and class method tests
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.
2024-03-09 19:35:54 +02:00
Ran Benita 774f0c44e6 fixtures: only call `instance` property once in function
No need to compute the property multiple times.
2024-03-09 10:16:41 +02:00
Ran Benita 006058f1f9 fixtures: update outdated comment
No longer does unittest stuff. Also the rest of the sentence is not
really necessary for a docstring.
2024-03-09 10:16:41 +02:00
Ran Benita 437eb86edd
Merge pull request #12092 from bluetech/fixture-cleanup
fixtures: a few more cleanups
2024-03-09 08:55:37 +02:00
Levon Saldamli 9033d4d3ff
Parse args from file (#12085)
Co-authored-by: Ran Benita <ran@unusedvar.com>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
2024-03-09 08:51:52 +02:00