Commit Graph

308 Commits

Author SHA1 Message Date
Pierre Sassoulas 4788165e69 [ruff UP031] Fix to use format specifiers instead of percent format 2024-04-30 18:06:26 +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
Bruno Oliveira acafd003aa
Consider pyproject.toml files for config if no other config files were found (#11962)
Today `pyproject.toml` is the standard for declaring a Python project root, so seems reasonable to consider it for the ini configuration (and specially `rootdir`) in case we do not find other suitable candidates.

Related to #11311
2024-02-14 16:08:45 -03:00
Bruno Oliveira 46e6fb12c7
Consider paths and pathlists relative to cwd in case of an absent ini-file (#11963)
Previously this would trigger an `AssertionError`.

While it could be considered a bug-fix, but given it now can be relied upon, it is probably better to consider it an improvement.

Fix #11311
2024-02-14 15:53:28 -03:00
Ran Benita d1ee6d154f Enable flake8-pie 2024-02-09 11:08:33 +02:00
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
Pierre Sassoulas 046f64751b Fix a duplicate assignment in test_config.py
Taken from https://github.com/pytest-dev/pytest/pull/11885 that was closed.
2024-01-31 13:59:25 +01:00
Bruno Oliveira 8b54596639 Run pre-commit on all files
Running pre-commit on all files after replacing reorder-python-imports by isort.
2024-01-30 16:35:46 -03:00
Bruno Oliveira 878af85aef
mypy: disallow untyped defs by default (#11862)
Change our mypy configuration to disallow untyped defs by default, which ensures *new* files added to the code base are fully typed.

To avoid having to type-annotate everything now, add `# mypy: allow-untyped-defs` to files which are not fully type annotated yet.

As we fully type annotate those modules, we can then just remove that directive from the top.
2024-01-28 10:12:42 -03:00
Ran Benita 676f38d04a findpaths: rely on invocation_dir instead of cwd
We should aim to remove all `cwd()` calls except one, otherwise things
will go bad if the working directory changes. Use the invocation dir
instead.
2024-01-18 12:35:32 +02:00
Ran Benita e1074f9c3d config: stop using exception triplets in `ConftestImportError`
In recent python versions all of the info is on the exception object
itself so no reason to deal with the annoying tuple.
2024-01-15 09:47:55 +02:00
Ran Benita f4e7b0d6e0 Remove deprecated `pytest_cmdline_preparse` hook 2024-01-02 12:20:47 +02:00
Ran Benita 385796ba49 Rework Session and Package collection
Fix #7777.
2023-12-10 17:01:39 +02:00
Ran Benita ef699f8c17 testing: remove a no longer necessary skip
pytest-xdist was released at 2019-02-15, seems enough time.
2023-11-30 19:53:31 +02:00
Patrick Lannigan 9dc1fc4523
Add verbosity_assertions and config.get_verbosity
Fixes #11387
2023-11-19 11:56:29 -03:00
Sharad Nair 7c7bdf4574
Sanitize ini-options default handling #11282 (#11594)
Fixes #11282
2023-11-11 13:08:18 -03:00
Jon Parise 7500fe44b2
Correct the spelling of ArgSource.INVOCATION_DIR (#11333)
Config.ArgsSource.INCOVATION_DIR remains as a backwards compatibility
alias.
2023-08-23 09:21:17 +00:00
Ran Benita 01ac13a77d config: split _getconftestmodules and _loadconftestmodules
Previously, the `_getconftestmodules` function was used both to load
conftest modules for a path (during `pytest_load_initial_conftests`),
and to retrieve conftest modules for a path (during hook dispatch and
for fetching `collect_ignore`). This made things muddy - it is usually
nicer to have clear separation between "command" and "query" functions,
when they occur in separate phases.

So split into "load" and "get".

Currently, `gethookproxy` still loads conftest itself. I hope to change
this in the future.
2023-08-01 09:46:17 +03:00
Ran Benita b41acaea12 Switch to new-style pluggy hook wrappers
Fix #11122.
2023-07-14 22:47:48 +03:00
Zac Hatfield-Dodds f4e3b4ad98 Drop Python 3.7 2023-06-30 14:55:42 -07:00
Ran Benita a4a189ad99 Change PytestRemovedIn8Warning to error by default
Per our backward compatibility policy.
2023-06-23 16:42:24 +03:00
nondescryptid a704605cf1 Fix encoding warnings 2023-06-20 04:55:39 -07:00
Ran Benita 4a1bba25b9 config: fallback confcutdir to rootpath if inipath is not set
Currently, if `--confcutdir` is not set, `inipath.parent` is used, and
if `initpath` is not set, then `confcutdir` is None, which means there
is no cutoff.

Having no cutoff is not great, it means we potentially start probing
stuff all the way up to the filesystem root directory. So let's add
another fallback, to `rootpath`, which is always something reasonable.
2023-05-30 19:52:59 +03:00
Chris Mahoney 4f3f36c396
Add alias `--config-file` to `-c` (#11036)
Fixes #11031

Signed-off-by: Chris Mahoney <chrismahoey@hotmail.com>
Co-authored-by: Chris Mahoney <chrismahoey@hotmail.com>
2023-05-26 07:56:18 -03:00
Ronny Pfannschmidt 407b330fe1 split up report header lines
i found it painful to read crammed in a single line
thus rootdir, config file and testpaths now have own lines
2023-03-17 21:58:26 +01:00
Yannick PÉROUX af4143729f
Allow spaces in -p arguments (#10658) 2023-01-21 08:22:44 -03:00
Ran Benita 310b67b227
Drop attrs dependency, use dataclasses instead (#10669)
Since pytest now requires Python>=3.7, we can use the stdlib attrs
clone, dataclasses, instead of the OG package.

attrs is still somewhat nicer than dataclasses and has some extra
functionality, but for pytest usage there's not really a justification
IMO to impose the extra dependency on users when a standard alternative
exists.
2023-01-20 11:13:36 +02:00
Gergely Kalmár adaa463ee3
Ignore editable installation modules (#10231)
Fixes #10230
2022-08-26 09:46:47 -03:00
Chris Wheeler fab696dcd1
Add support for .pytest.ini as an alternative to pytest.ini
Closes #9987
2022-06-14 08:24:35 -03:00
Hugo van Kemenade e54c6a1362
Document the --code-highlight default (#9883)
Also normalized all help text using the patterns:

* `One sentence help text`
* `First sentence of help. Second sentence of help.`
2022-05-31 16:32:51 -03:00
Tobias Diez 141b301d3d
Fix more tests 2022-03-29 12:34:15 +02:00
Bruno Oliveira e38d1cac48 Improve error message for malformed pyproject.toml files
Including the file name is enough to let the user know what the problem is.

The same is not needed for `.ini` files because the error message includes the path to the file by default.

Fix #9730
2022-03-05 08:59:28 -03:00
Ran Benita 01e1de7a1a Rename ``pythonpath`` plugin to ``python_path``
Fix #9636.
2022-02-09 10:03:20 +02:00
Ran Benita 3f4eab3f8f testing: avoid private pluggy attributes in test 2022-01-14 17:49:38 +02:00
Bruno Oliveira 696f955ff8 Split wrappers and non-wrappers in test_load_initial_conftest_last_ordering
Seems better to test which one is which explicitly.
2022-01-04 10:03:30 -03:00
Bruno Oliveira 4038752bf3 Ensure Config.inifile is available during pytest_cmdline_main
Fix #9396
2022-01-04 10:03:28 -03:00
Kian Meng, Ang 55debfad1f
Fix typos (#9424) 2021-12-27 09:23:15 -03:00
Ran Benita ce7cff9f8e Move pathlist support to legacypath plugin 2021-10-28 21:51:51 +03:00
Bruno Oliveira f5fd2fb176 Improve UX during errors while parsing warning filters
Fix #7864
Fix #9218

Closes #8343
Closes #7877
2021-10-21 13:15:41 -03:00
Ran Benita 5059b31a73 Remove redundant explicit os.fspath calls
Python calls it on its own.
2021-10-09 13:44:44 +03:00
Brian Okken c82bda259c
Add a `pythonpath` setting to allow paths to be added to `sys.path`. (#9134) 2021-10-05 09:36:38 +03:00
Simon K d5c62d0326
Making `--debug` more configurable for the pytest user (#8955)
Close #8954
2021-07-30 17:37:38 -03:00
Bruno Oliveira 109312ba86 Make --version write to stdout rather than stderr
Fix #8246
2021-06-28 15:56:26 -03:00
Ran Benita 113a860a1f argparsing: support parser.addini(type="paths") which returns pathlib.Paths 2021-05-07 09:58:51 +03:00
Florian Bruhin e354c5c919 Fix warning filters used in tests 2021-05-04 17:25:02 +02:00
Abdelrahman Elbehery 9078c3ce23
fix #8464 wrong root dir when -c is passed (#8537)
fix #8464 wrong root dir when -c is passed
2021-04-16 14:38:35 -03:00
Tadeu Manoel b706a2c048
Fix error with --import-mode=importlib and modules containing dataclasses or pickle (#7870)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

Fixes #7856, fixes #7859
2021-04-05 17:10:03 -03:00
Florian Bruhin bc055e8e69
Fix required_plugins with prereleases (#8469)
* Fix required_plugins with prereleases

Fixes #8456

* Fix existing tests

* Update changelog/8456.bugfix.rst

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2021-03-21 22:51:12 +01:00
Ran Benita 59251e8a2a Remove/replace some unneeded usages of py.path 2021-03-14 14:12:28 +02:00
Ronny Pfannschmidt dbed1ff68f adopt main terminology in the configs
ref pytest-dev/meta#8
2021-03-09 22:35:34 +01:00