Commit Graph

3385 Commits

Author SHA1 Message Date
Virendra Patil 49bb5c89a6
Improved handling of invalid regex pattern in pytest.raises (#12526) 2024-07-02 21:58:08 +03:00
Bruno Oliveira f502f1db31 Update src/_pytest/reports.py 2024-07-01 13:23:53 +02:00
Bruno Oliveira 201ed9f6a5 Update src/_pytest/reports.py 2024-07-01 13:23:53 +02:00
pre-commit-ci[bot] 2c1ed505d9 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-07-01 13:23:53 +02:00
Bruno Oliveira 269ded17a6 Update src/_pytest/reports.py 2024-07-01 13:23:53 +02:00
Pavel Březina 41ca4dd44e testresult: correctly apply verbose word markup and avoid crash
The following snippet would have resulted in crash on multiple places since
`_get_verbose_word` expects only string, not a tuple.

```python
    @pytest.hookimpl(tryfirst=True)
    def pytest_report_teststatus(report: pytest.CollectReport | pytest.TestReport, config: pytest.Config):
        if report.when == "call":
            return ("error", "A",  ("AVC", {"bold": True, "red": True}))

        return None
```

```
Traceback (most recent call last):
  File "/home/pbrezina/workspace/sssd/.venv/bin/pytest", line 8, in <module>
    sys.exit(console_main())
             ^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/config/__init__.py", line 207, in console_main
    code = main()
           ^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/config/__init__.py", line 179, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/main.py", line 333, in pytest_cmdline_main
    return wrap_session(config, _main)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/main.py", line 321, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/logging.py", line 872, in pytest_sessionfinish
    return (yield)
            ^^^^^
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_callers.py", line 124, in _multicall
    teardown.send(result)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/terminal.py", line 899, in pytest_sessionfinish
    self.config.hook.pytest_terminal_summary(
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/pbrezina/workspace/sssd/.venv/lib64/python3.11/site-packages/pluggy/_callers.py", line 124, in _multicall
    teardown.send(result)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/terminal.py", line 923, in pytest_terminal_summary
    self.short_test_summary()
  File "/home/pbrezina/workspace/pytest/src/_pytest/terminal.py", line 1272, in short_test_summary
    action(lines)
  File "/home/pbrezina/workspace/pytest/src/_pytest/terminal.py", line 1205, in show_simple
    line = _get_line_with_reprcrash_message(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/terminal.py", line 1429, in _get_line_with_reprcrash_message
    word = tw.markup(verbose_word, **word_markup)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pbrezina/workspace/pytest/src/_pytest/_io/terminalwriter.py", line 114, in markup
    text = "".join(f"\x1b[{cod}m" for cod in esc) + text + "\x1b[0m"
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
TypeError: can only concatenate str (not "tuple") to str
```

Signed-off-by: Pavel Březina <pbrezina@redhat.com>
2024-07-01 13:23:53 +02:00
Zach Snicker 0adcc21f48
Support venv detection on Windows with mingw Python (#12545)
Closes #12544
2024-06-29 00:30:51 +03:00
joseph-sentry 0ed2d79457
junitxml: add timezone to testsuite timestamp (#12491)
Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>
Co-authored-by: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de>
2024-06-27 09:41:02 -03:00
lovetheguitar 36b384afc7 docs(expression.py): simplify grammar documentation by defining `kwargs` separately 2024-06-25 09:18:18 +02:00
lovetheguitar dd57196953 perf(expression): define `TokenType.STRING` as "string literal" for clearer errors 2024-06-25 09:18:18 +02:00
lovetheguitar 540ede3439 docs(expression.py): describe new `name` & `value` productions 2024-06-25 09:18:18 +02:00
lovetheguitar 3cce243774 docs(expression.py): fix typo 2024-06-22 20:16:24 +02:00
lovetheguitar 73bc35ce2b docs(expression.py): correct grammar definition of lexer 2024-06-22 20:16:24 +02:00
Sviatoslav Sydorenko (Святослав Сидоренко) 75a2225ed1
🔥 Drop the missing kwargs case 2024-06-21 22:09:45 +02:00
lovetheguitar b1255a9aae style(mark): type hint `**kwargs` as `str | int | bool | None` 2024-06-21 20:51:01 +02:00
lovetheguitar 6dd8ad60a4 refactor(MarkMatcher): replace `from_item` with `from_markers` method 2024-06-21 20:51:01 +02:00
lovetheguitar 1e7eb20347 perf(expression): improve string lexing & error messages 2024-06-21 20:51:01 +02:00
lovetheguitar f4897391ec refactor(mark): use existing `NOT_SET` sentinel 2024-06-21 20:51:01 +02:00
lovetheguitar 04f457c4f4 style: use `@overload` to get rid of mypy only assertions 2024-06-21 20:51:01 +02:00
lovetheguitar 15c33fbaa3 feat: support keyword arguments in marker expressions
Fixes #12281
2024-06-21 20:51:01 +02:00
Farbod Ahmadian 34e28295a7
refactor: simplify bound method representation (#12492)
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
Co-authored-by: Farbod Ahmadian <farbod@datachef.com>
2024-06-21 18:20:44 +02:00
Ronny Pfannschmidt bbe6b4a218
Merge pull request #12467 from RonnyPfannschmidt/ronny/new-annotations-try-2
from __future__ import annotations + migrate
2024-06-21 10:24:56 +02:00
Ronny Pfannschmidt 6a8e9ed43a fixup: Config.cache cannot be None 2024-06-21 09:42:24 +02:00
Ronny Pfannschmidt 5e1649f59a resolve most sphinx lookup errors
add the extra sphinx annotations to refer to Path instances

add Path to nitpicky ignore
2024-06-20 11:04:33 +02:00
Ronny Pfannschmidt b7c0295e1a use runtime union for EXCEPTION_OR_MORE 2024-06-20 11:03:07 +02:00
Ronny Pfannschmidt 9295f9ffff RFC: from __future__ import annotations + migrate 2024-06-20 11:03:03 +02:00
Sviatoslav Sydorenko 39b548e6ea
📝 Make "setuptools entrypoint" term generic
This feature grew out of `setuptools` but the modern interface for
extracting this information from the distribution package metadata
is `importlib.metadata`. So the patch attempts to reflect this in
the documentation messaging.

Refs:
* https://docs.python.org/3/library/importlib.metadata.html#entry-points
* https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/#using-package-metadata
* https://packaging.python.org/en/latest/specifications/entry-points/#entry-points
2024-06-20 11:01:10 +02:00
Ronny Pfannschmidt 76f3f3da00 fix #11797: be more lenient on SequenceLike approx
this needs a validation as it allows partially implemented sequences
2024-06-18 17:01:24 +02:00
Sviatoslav Sydorenko (Святослав Сидоренко) 49374ec7a0
🚑 Clarify patch condition for doctest finder hack (#12471)
There was a regression caused by #12431 that excluded the patch on
broken CPython patch version ranges 3.11.0–3.11.8 and 3.12.0–3.12.2.

This change fixes that by adjusting the patching conditional clause
to include said versions.

Closes #12430.

Co-authored-by: Florian Bruhin <me@the-compiler.org>
2024-06-18 09:21:25 +00:00
pre-commit-ci[bot] ff75980135
[pre-commit.ci] pre-commit autoupdate (#12447)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.7 → v0.4.8](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.7...v0.4.8)
- [github.com/asottile/pyupgrade: v3.15.2 → v3.16.0](https://github.com/asottile/pyupgrade/compare/v3.15.2...v3.16.0)

* Apply pyupgrade automatically

---------

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-06-11 12:36:39 -03:00
Ran Benita 23ca9798f7
doc: fix broken code blocks (#12449)
Caused by 4588653b24.

The issue was fixed in https://github.com/astral-sh/ruff/issues/11577,
so won't trigger again.

Fix #12437.
2024-06-11 12:36:20 -03:00
Ran Benita 7ef9da1f02 terminalwriter: improve `PYTEST_THEME`, `PYTEST_THEME_MODE` usage errors 2024-06-10 11:50:08 +03:00
Ran Benita 67a570aea9 terminalwriter: factor out pygments lexer & formatter selection to own functions
We intend to add some more logic here.
2024-06-10 11:48:19 +03:00
Ran Benita f85289ba87
Merge pull request #12436 from bluetech/unittest-rerun-assertion
unittest: fix assertion errors on unittest reruns
2024-06-08 02:11:20 +03:00
Ran Benita 18f15a38fc
Merge pull request #12435 from bluetech/avoid-type-checking
Avoid some `TYPE_CHECKING`
2024-06-08 02:11:06 +03:00
Ran Benita db67107090
Merge pull request #12434 from bluetech/register-fixture-scope-none
fixtures: change `register_fixture` to not accept `scope=None`
2024-06-07 12:11:56 +03:00
Ran Benita de47b73520 unittest: fix assertion errors on unittest reruns
This fixes unittest test reruns when using plugins like
pytest-rerunfailures.

The `instance` property uses AttributeError to check if the instance
needs to be initialized, so `del` is the correct way to clear it, not
setting to `None`.

Regressed in 8.2.2.
2024-06-07 10:21:15 +03:00
Ran Benita c07bbdfa5b Avoid some TYPE_CHECKING
It's better not to use it when possible.
2024-06-07 09:36:55 +03:00
Jason R. Coombs f941099371
Cleanup MockAwareDocTestFinder. (#12431)
* Only rely on _find_lineno on Python 3.10 and earlier.

* Update docstring to reflect current expectation.

* Only rely on _find on Python 3.9 and earlier.

* Mark line as uncovered.

* Remove empty else block (implicit is better than explicit).

Closes #12430
Closes #12432
2024-06-07 09:32:33 +03:00
Ran Benita c9d8765381 fixtures: change `register_fixture` to not accept `scope=None`
There is no reason to allow this.
2024-06-04 23:22:18 +03:00
Ran Benita d4dbe771f0
Merge pull request #12409 from bluetech/reorder-items-perf
fixtures: fix catastrophic performance problem in `reorder_items`
2024-06-04 10:16:19 +03:00
Ran Benita e89d23b247 fixtures: fix catastrophic performance problem in `reorder_items`
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.
2024-06-04 10:15:50 +03:00
Michael Vogt 7be95f9b30
code: do not truncate args when running with -vvv (#12241)
Related to #2871.
2024-06-03 12:11:41 +00:00
Ran Benita 1eee63a891 fixtures: minor cleanups to reorder_items
This makes some minor clarity and performance improvements to the code.
2024-06-02 18:31:54 +03:00
Ran Benita 17065cb008 cacheprovider: fix "Directory not empty" crash from cache directory creation
Fix #12381

Test plan:
It's possible to write a deterministic test case for this, but somewhat
of a hassle so I tested it manually. I reproduced by removing existing
`.pytest_cache`, adding a sleep before the rename and running two
pytests. I verified that it doesn't reproduce after the fix.
2024-06-02 17:05:36 +03:00
Pierre Sassoulas 0d33cdf02a [pylint] Disable the only 'misplaced-bare-raise' 2024-05-29 14:36:01 +02:00
Pierre Sassoulas db67d5c874 [pylint 'use-yield-from'] Fix all occurences in existing code 2024-05-29 14:36:01 +02:00
Bruno Oliveira 9f121e85a7
Clarify pytest_ignore_collect docs (#12385)
Fixes #12383

Co-authored-by: Ran Benita <ran@unusedvar.com>
2024-05-28 13:47:00 -03:00
pre-commit-ci[bot] 48cb8a2b32
[pre-commit.ci] pre-commit autoupdate (#12380)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.4 → v0.4.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.4...v0.4.5)

* [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>
2024-05-27 22:31:18 +00:00
Pierre Sassoulas 88fae23bdd
[pylint] Fixes all ``use-maxplit-args``, ``consider-using-enumerate`` (#12172)
* [pylint 'use-maxsplit-arg'] Do not split more than necessary when using the first element

* [pylint 'consider-using-enumerate'] Use zip when iterating on two iterators

* [pylint] 'cell-var-from-loop' and 'disallowed-name' permanent disable

* [pylint] Disable 'possibly-used-before-assignment' following 3.2.0 release
2024-05-27 12:18:03 -07:00