Commit Graph

4931 Commits

Author SHA1 Message Date
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 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
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 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
pre-commit-ci[bot] fafab1dbfd
[pre-commit.ci] pre-commit autoupdate (#12238)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.7 → v0.4.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.7...v0.4.1)
- [github.com/tox-dev/pyproject-fmt: 1.7.0 → 1.8.0](https://github.com/tox-dev/pyproject-fmt/compare/1.7.0...1.8.0)

* noqa a test

---------

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>
2024-04-23 11:59:12 -03: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 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 ad95d59d61
Use monkeypatch in test_pytest_version_env_var
Follow up to #12190
2024-04-18 23:05:29 -03: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
Ran Benita 1f001cd105
Merge pull request #12199 from tamird/mkdir-test-init
Add test for Cache.mkdir
2024-04-09 22:26:36 +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
Tamir Duberstein e06c337bd8
Add test for Cache.mkdir 2024-04-08 15:08:18 +01:00
Tamir Duberstein a02cc0ad1b
Add types 2024-04-08 15:08:17 +01:00
dependabot[bot] 74f05648d5
build(deps): Bump django in /testing/plugins_integration (#12196)
Bumps [django](https://github.com/django/django) from 5.0.3 to 5.0.4.
- [Commits](https://github.com/django/django/compare/5.0.3...5.0.4)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 12:15:01 +02: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 aa5324560b
Merge pull request #12159 from pytest-dev/dependabot/pip/testing/plugins_integration/pytest-cov-5.0.0
build(deps): Bump pytest-cov from 4.1.0 to 5.0.0 in /testing/plugins_integration
2024-04-02 22:59:20 +03: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
dependabot[bot] 5d345f6d7f
build(deps): Bump pytest-cov in /testing/plugins_integration
Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 4.1.0 to 5.0.0.
- [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest-cov/compare/v4.1.0...v5.0.0)

---
updated-dependencies:
- dependency-name: pytest-cov
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-25 06:32:55 +00:00
dependabot[bot] 2cba2237cd
build(deps): Bump pytest-twisted in /testing/plugins_integration (#12158)
Bumps [pytest-twisted](https://github.com/pytest-dev/pytest-twisted) from 1.14.0 to 1.14.1.
- [Release notes](https://github.com/pytest-dev/pytest-twisted/releases)
- [Commits](https://github.com/pytest-dev/pytest-twisted/compare/v1.14.0...v1.14.1)

---
updated-dependencies:
- dependency-name: pytest-twisted
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-25 07:32:29 +01:00
dependabot[bot] e7b048e92d
build(deps): Bump pytest-mock in /testing/plugins_integration (#12160)
Bumps [pytest-mock](https://github.com/pytest-dev/pytest-mock) from 3.12.0 to 3.14.0.
- [Release notes](https://github.com/pytest-dev/pytest-mock/releases)
- [Changelog](https://github.com/pytest-dev/pytest-mock/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest-mock/compare/v3.12.0...v3.14.0)

---
updated-dependencies:
- dependency-name: pytest-mock
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-25 07:30:45 +01:00
dependabot[bot] 4a8cefbf64
build(deps): Bump pytest-asyncio in /testing/plugins_integration (#12161)
Bumps [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) from 0.23.5 to 0.23.6.
- [Release notes](https://github.com/pytest-dev/pytest-asyncio/releases)
- [Commits](https://github.com/pytest-dev/pytest-asyncio/compare/v0.23.5...v0.23.6)

---
updated-dependencies:
- dependency-name: pytest-asyncio
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-25 07:30:08 +01:00
dependabot[bot] 6be5c9d88c
build(deps): Bump pytest-rerunfailures in /testing/plugins_integration
Bumps [pytest-rerunfailures](https://github.com/pytest-dev/pytest-rerunfailures) from 13.0 to 14.0.
- [Changelog](https://github.com/pytest-dev/pytest-rerunfailures/blob/master/CHANGES.rst)
- [Commits](https://github.com/pytest-dev/pytest-rerunfailures/compare/13.0...14.0)

---
updated-dependencies:
- dependency-name: pytest-rerunfailures
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-18 03:02:28 +00: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
jakkdl bec0e9caf8 Add tests to ensure setup&finalization for scoped fixtures only run once. 2024-03-15 12:26:28 +01: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
dependabot[bot] 122b43439c
build(deps): Bump django in /testing/plugins_integration (#12103)
Bumps [django](https://github.com/django/django) from 5.0.2 to 5.0.3.
- [Commits](https://github.com/django/django/compare/5.0.2...5.0.3)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 07:05:41 +01: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 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
Bruno Oliveira 2ccc73be9a
Merge pull request #12087 from nicoddemus/revert-path-deprecations
Revert legacy path removals
2024-03-08 20:06:47 -03:00
Ran Benita 71671f60b5 fixtures: improve fixture scope mismatch message
- 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.
2024-03-09 00:02:06 +02:00
Ran Benita 83887c066b
Merge pull request #12089 from bluetech/unittest-obj
unittest: make `obj` work more like `Function`/`Class`
2024-03-08 20:50:27 +02:00
Ran Benita 51595d9000
Merge pull request #12056 from pytest-dev/dependabot/pip/testing/plugins_integration/twisted-24.3.0
build(deps): Bump twisted from 23.10.0 to 24.3.0 in /testing/plugins_integration
2024-03-08 14:07:02 +02:00
Ran Benita 1a5e0eb71d unittest: make `obj` work more like `Function`/`Class`
Previously, the `obj` of a `TestCaseFunction` (the unittest plugin item
type) was the unbound method. This is unlike regular `Class` where the
`obj` is a bound method to a fresh instance.

This difference necessitated several special cases in in places outside
of the unittest plugin, such as `FixtureDef` and `FixtureRequest`, and
made things a bit harder to understand.

Instead, match how the python plugin does it, including collecting
fixtures from a fresh instance.

The downside is that now this instance for fixture-collection is kept
around in memory, but it's the same as `Class` so nothing new. Users
should only initialize stuff in `setUp`/`setUpClass` and similar
methods, and not in `__init__` which is generally off-limits in
`TestCase` subclasses.

I am not sure why there was a difference in the first place, though I
will say the previous unittest approach is probably the preferable one,
but first let's get consistency.
2024-03-08 14:03:26 +02:00
Bruno Oliveira dacee1f11d Revert "Remove deprecated py.path hook arguments"
This reverts commit a98f02d423.
2024-03-07 19:50:33 -03:00
Bruno Oliveira 303cd0d48a Revert "Remove deprecated py.path (`fspath`) node constructor arguments"
This reverts commit 6c89f9261c.
2024-03-07 19:50:33 -03:00
Bruno Oliveira 03e54712dd
Do not import duplicated modules with --importmode=importlib (#12074)
Regression brought up by #11475.
2024-03-04 12:44:56 -03:00
dependabot[bot] 23bdc643c9
build(deps): Bump twisted in /testing/plugins_integration
Bumps [twisted](https://github.com/twisted/twisted) from 23.10.0 to 24.3.0.
- [Release notes](https://github.com/twisted/twisted/releases)
- [Changelog](https://github.com/twisted/twisted/blob/trunk/NEWS.rst)
- [Commits](https://github.com/twisted/twisted/compare/twisted-23.10.0...twisted-24.3.0)

---
updated-dependencies:
- dependency-name: twisted
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-04 03:25:34 +00:00
Ran Benita f4e10251a4
Merge pull request #12048 from bluetech/fixture-teardown-excgroup
fixtures: use exception group when multiple finalizers raise in fixture teardown
2024-03-03 15:09:36 +02:00
Ran Benita 43492f5707
Merge pull request #12051 from jakkdl/test_debugging_pythonbreakpoint
[minor/QoL] monkeypatch.delenv PYTHONBREAKPOINT in two tests that previously failed/skipped
2024-03-03 15:07:19 +02:00
jakkdl 5e2ee7175c monkeypatch.delenv PYTHONBREAKPOINT in two tests that previously failed/skipped 2024-03-03 13:48:29 +01:00
Bruno Oliveira 89ee4493cc
Merge pull request #11997 from nicoddemus/11475-importlib
Change importlib to first try to import modules using the standard mechanism
2024-03-03 09:43:14 -03:00
mrbean-bremen 8248946a55
Do not collect symlinked tests under Windows (#12050)
The check for short paths under Windows via os.path.samefile, introduced in #11936, also found similar tests in symlinked tests in the GH Actions CI.

Fixes #12039.

Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
2024-03-03 09:41:31 -03:00
Ran Benita 434282e17f fixtures: use exception group when multiple finalizers raise in fixture teardown
Previously, if more than one fixture finalizer raised, only the first
was reported, and the other errors were lost.

Use an exception group to report them all. This is similar to the change
we made in node teardowns (in `SetupState`).
2024-03-02 23:39:11 +02:00