Commit Graph

32 Commits

Author SHA1 Message Date
Pierre Sassoulas 4588653b24 Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff
ruff is faster and handle everything we had prior.

isort configuration done based on the indication from
https://github.com/astral-sh/ruff/issues/4670, previousely based on
reorder-python-import (#11896)

flake8-docstrings was a wrapper around pydocstyle (now archived) that
explicitly asks to use ruff in https://github.com/PyCQA/pydocstyle/pull/658.

flake8-typing-import is useful mainly for project that support python 3.7
and the one useful check will be implemented in https://github.com/astral-sh/ruff/issues/2302

We need to keep blacken-doc because ruff does not handle detection
of python code inside .md and .rst. The direct link to the repo is
now used to avoid a redirection.

Manual fixes:
- Lines that became too long
- % formatting that was not done automatically
- type: ignore that were moved around
- noqa of hard to fix issues (UP031 generally)
- fmt: off and fmt: on that is not really identical
  between black and ruff
- autofix re-order in pre-commit from faster to slower

Co-authored-by: Ran Benita <ran@unusedvar.com>
2024-02-02 09:27:00 +01:00
Jens Tröger acab13fcc9
Add new filtering() method to LogCaptureFixture class (#11625)
Fixes #11610
2023-11-24 09:38:34 -03:00
Bruno Oliveira 7e69ce7449 Add full type annotations to logging/test_fixture.py 2023-10-23 10:46:55 -03:00
Bruno Oliveira 395bbae8a2 Ensure logging tests always cleanup after themselves
Logging has many global states, and we did foresee this by creating a ``cleanup_disabled_logging`` fixture,
however one might still forget to use it and failures leak later -- sometimes not even in the same PR, because the order
of the tests might change in the future, specially when running under xdist.

This problem surfaced during pytest-dev/pytest#11530, where tests unrelated to the change started to fail.
2023-10-23 10:46:55 -03:00
Alex Lambson ba32a3bd87
Handle disabled logging in 'caplog.set_level' and 'caplog.at_level' (#8758)
Forces requested `caplog` logging levels to be enabled if they were disabled via `logging.disable()`

`[attr-defined]` mypy error ignored in `logging.py` because there were existing errors with the imports
and `loggin.Logger.manager` is an attr set at runtime. Since it's in the standard lib I can't really fix that.

Ignored an attr-defined error in `src/_pytest/config/__init__.py` because the re-export is necessary.

Fixes #8711
2023-05-18 10:18:59 -03:00
zx.qiu f29f79e39f Use records.clear() in LogCaptureHandler when caplog.clear() 2022-06-24 23:04:04 +08:00
zx.qiu c7e784f95d Fix stage caplog records not clear
Closes #9877
2022-06-24 23:03:37 +08:00
Ran Benita 2aaea20cb2 Use {node,config}.stash instead of ._store
Use the public name. The `_store` name is only because some plugins
started using it anyway - will be removed at some point.
2021-07-24 17:40:08 +03:00
Anton 8eef8c6004
tests: Migrate to pytester - incremental update (#8145) 2020-12-15 13:02:32 +02:00
Ran Benita b1354608cc logging: fix handler level restored incorrectly if caplog.set_level is called more than once 2020-08-22 17:46:23 +03:00
Ran Benita b8471aa527 testing: fix some docstring issues
In preparation for enforcing some docstring lints.
2020-08-03 10:10:43 +03:00
Ran Benita 0e0275d8d9 logging: fix capture handler level not reset on teardown after caplog.set_level()
This probably regressed in fcbaab8.
2020-07-29 14:59:29 +03:00
Ruaridh Williamson 304f2916fc logging: use unique handlers for caplog and reports
Setting log_level via the CLI or .ini will control the log level of the
report that is dumped upon failure of a test.

If caplog modified the log level during the execution of that test, it
should not impact the level that is displayed upon failure in the
"captured log report" section.

[
ran:
- rebased
- reused handler
- changed store keys also to "caplog_handler_*"
- added changelog
all bugs are mine :)
]
2020-07-01 19:30:03 +03:00
Bruno Oliveira fcbaab8b0b
Allow tests to override "global" `log_level` (rebased) (#7340)
Co-authored-by: Ruaridh Williamson <ruaridh.williamson@flexciton.com>
2020-06-08 22:05:46 -03:00
Ran Benita d2d11a8bdc logging: reuse LoggingCaptureHandler instance since it's expensive to create
Previously, a LoggingCaptureHandler was instantiated for each test's
setup/call/teardown which turns out to be expensive.

Instead, only keep one instance and reset it between runs.
2020-05-18 11:27:50 +03:00
Ran Benita ac6c02f1e2 logging: use item's store for private attributes
This makes things type-safe and properly private.
2020-05-17 20:42:05 +03:00
Bruno Oliveira 47c2091ecd Use new no-match functions to replace previous idiom 2019-10-06 18:05:24 -03:00
Anthony Sottile a91fe1fedd pre-commit run pyupgrade --all-files 2019-06-03 12:08:02 -03:00
Anthony Sottile 5034399d7a pre-commit run fix-encoding-pragma --all-files 2019-06-03 12:08:01 -03:00
Daniel Hahler 4a74d455de minor: typos 2018-11-09 02:03:44 +01:00
Anthony Sottile 3901569f26 Improve performance of ~3 of the slowest tests 2018-10-08 11:12:55 -07:00
Wil Cooley 3615977608 Add `messages` property to `caplog` fixture. 2018-06-14 12:22:33 -07:00
Ronny Pfannschmidt 703e4b11ba run black 2018-05-23 16:48:46 +02:00
Kostis Anagnostopoulos 68375513f3 Add TC to demonstrate #3297 that caplog.clear() does not clean text 2018-03-13 00:28:47 +02:00
Bruno Oliveira 15cbd61159 Change caplog.get_handler(when) to caplog.get_records(when)
While updating the docs I noticed that caplog.get_handler() exposes
the underlying Handler object, which I think it is a bit too much
detail at this stage. Update to return the records directly instead.
2018-01-24 19:08:49 -02:00
Bruno Oliveira 2e40a8b3ca Fix test_caplog_captures_for_all_stages by setting log level 2018-01-20 12:04:28 -02:00
Bruno Oliveira aca1b06747 Undo log level set by caplog.set_level at the end of the test
Otherwise this leaks the log level information to other tests

Ref: #3013
2018-01-20 12:01:42 -02:00
Anders Hovmöller 7ea5a22657 Access captures logs in teardown 2018-01-19 12:42:35 +01:00
Bruno Oliveira 6b86b0dbfe Fix additional linting issues 2017-10-24 21:01:00 -02:00
Thomas Hisch 815dd19fb4 Remove unicode literal compat code 2017-10-12 02:19:24 +02:00
Thomas Hisch ad21d5cac4 Remove pytest-capturelog backward compat code 2017-09-26 23:24:27 +02:00
Thomas Hisch 6607478b23 Add unittests for LoggingPlugin (excluding perf tests) 2017-09-22 22:27:49 +02:00