Commit Graph

115 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
Bruno Oliveira 111c0d910e Add consider_namespace_packages ini option
Fix #11475
2024-03-02 16:13:48 -03: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
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 34fafe4c6b config: avoid Path.cwd() call in `_set_initial_conftests`
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 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
Zac Hatfield-Dodds 661b938fca Add encoding in more tests 2023-06-20 04:55:40 -07:00
nondescryptid a704605cf1 Fix encoding warnings 2023-06-20 04:55:39 -07:00
Ran Benita 14890329dc config: fix the paths considered for initial conftest discovery
Fixes #11104.

See the issue for a description of the problem.

Now, we use the same logic for initial conftest paths as we do for
deciding the initial args, which was the idea behind checking
`namespace.file_or_dir` and `testpaths` previously.

This fixes the issue of `testpaths` being considered for initial
conftests even when it's not used for the args.

(Another issue in faeb16146b was that the
`testpaths` were not glob-expanded, this is also fixed.)
2023-06-21 09:01:42 +03: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
Bruno Oliveira faeb16146b Consider testpaths for initial conftests
The 'testpaths' option is meant to be identical to execute
pytest passing the 'testpaths' directories explicitly.

Fix #10987
2023-05-12 09:34:15 -03:00
Ran Benita 644a81af37 testing: fix Path.rglob("") failures in Python 3.11b1
Fix #9930.
2022-05-09 12:52:57 +03:00
Ran Benita 1d70b022f0 config: restore pre-pytest 7.1.0 confcutdir exclusion behavior
The change from `path not in confuctdir.parents` to the `relative_to`
check in 0c98f19231 broke picking up
conftest files when running against an installed package/site-packages.
See the issue for more details.

Fix #9767.
2022-03-16 22:55:06 +02:00
Ran Benita 161bc48117 config: get rid of _conftestpath2mod
It duplicates what PluginManager already knows, and no longer needed now
that symlinks are not resolved (see previous commit).
2022-01-09 12:33:45 +02:00
Anthony Sottile b0aabe4081 fix mypy 0.930 errors 2021-12-30 06:19:29 -08:00
Bruno Oliveira a335ade1f5
Rename pathlib hook parameters (#9363)
* Rename pytest_ignore_collect fspath parameter to collection_path

* Rename pytest_collect_file fspath parameter to file_path

* Rename pytest_pycollect_makemodule fspath parameter to module_path

* Rename pytest_report_header startpath parameter to start_path

* Rename pytest_report_collectionfinish startpath parameter to start_path

* Update docs with the renamed parameters

* Use pytest-flakes fork temporarily to prove it works

* Use pytest-flakes 4.0.5
2021-12-03 13:14:09 +01: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
Ran Benita f0c7043138 Remove/replace some more unnecessary uses of py.path 2021-03-15 10:39:44 +02:00
Matthew Hughes c9bb4c418f fixup! Rename variables 'tmpdir'->'tmp_path'
* Add some more of these
* Also reintroduce+rename instances of fixture usages that were
'tmpdir'->'tmp_path'
2021-02-21 13:10:07 +00:00
Anton 8eef8c6004
tests: Migrate to pytester - incremental update (#8145) 2020-12-15 13:02:32 +02:00
Ran Benita ed658d6829 Some py.path.local -> pathlib.Path
- Some conftest related functions
- _confcutdir
- Allow arbitrary os.PathLike[str] in gethookproxy.
2020-12-12 17:33:28 +02:00
Garvit Shubham 6fe9d2fb9f testing: convert test_{conftest,recwarn,tmpdir} to pytester 2020-11-16 19:22:57 +02:00
Anthony Sottile fb1d550aac py36+: remove rexport of Path and PurePath 2020-10-03 12:16:52 -07:00
Bruno Oliveira ef946d557c Remove resultlog plugin 2020-08-19 08:14:28 -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 c15bb5d3de pathlib: replace py.path.local.visit() with our own function
Part of reducing dependency on `py`. Also enables upcoming improvements.

In cases where there are simpler alternatives (in tests), I used those.

What's left are a couple of uses in `_pytest.main` and `_pytest.python`
and they only have modest requirements, so all of the featureful code
from py is not needed.
2020-07-25 00:26:49 +03:00
Bruno Oliveira ab6dacf1d1
Introduce --import-mode=importlib (#7246)
Fix #5821

Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-06-13 11:29:01 -03:00
Fabio Zadrozny 322190fd84
Fix issue where working dir becomes wrong on subst drive on Windows. Fixes #5965 (#6523)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-06-08 10:56:40 -03:00
Ran Benita d33da078a8 Move ExitCode's definition from _pytest.main to _pytest.config
ExitCode is used in several internal modules and hooks and so with type
annotations added, needs to be imported a lot.

_pytest.main, being the entry point, generally sits at the top of the
import tree.

So, it's not great to have ExitCode defined in _pytest.main, because it
will cause a lot of import cycles once type annotations are added (in
fact there is already one, which this change removes).

Move it to _pytest.config instead.

_pytest.main still imports ExitCode, so importing from there still
works, although external users should really be importing from `pytest`.
2020-02-10 23:55:06 +02:00
Daniel Hahler 5049e25a6a tests: cleanup unused fixtures 2020-01-16 21:12:48 +01:00
Daniel Hahler 5979837c60 Import Path from _pytest.pathlib for py35
This is important for `isinstance` checks etc.
2019-11-15 22:19:53 +01:00
Bruno Oliveira 47c2091ecd Use new no-match functions to replace previous idiom 2019-10-06 18:05:24 -03:00
Bruno Oliveira b48f51eb03 Use Path() objects to store conftest files
Using Path().resolve() is better than py.path.realpath because
it resolves to the correct path/drive in case-insensitive file systems (#5792):

>>> from py.path import local
>>> from pathlib import Path
>>>
>>> local('d:\\projects').realpath()
local('d:\\projects')
>>> Path('d:\\projects').resolve()
WindowsPath('D:/projects')

Fix #5819
2019-09-12 08:05:50 -03:00
Bruno Oliveira cf5b544db3 Revert "Merge pull request #5792 from dynatrace-oss-contrib/bugfix/badcase"
This reverts commit 955e542210, reversing
changes made to 0215bcd84e.

Will attempt a simpler approach
2019-09-12 08:05:43 -03:00
Christian Neumüller 29bb0eda27 Move _uniquepath to pathlib as unique_path.
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2019-08-28 12:29:41 +02:00
Christian Neumüller 1aac64573f black formatting. 2019-08-27 16:16:45 +02:00
Christian Neumüller 505c3340bf Fix pytest with mixed up filename casing. 2019-08-26 17:18:46 +02:00
Ronny Pfannschmidt 2b92fee1c3 initial conversion of exit codes to enum 2019-06-15 06:48:00 +02:00
Anthony Sottile a91fe1fedd pre-commit run pyupgrade --all-files 2019-06-03 12:08:02 -03:00
Anthony Sottile 3f1ec520fc pre-commit run reorder-python-imports --all-files 2019-06-03 12:08:01 -03:00
Anthony Sottile 5034399d7a pre-commit run fix-encoding-pragma --all-files 2019-06-03 12:08:01 -03:00
Anthony Sottile dc75b6af47 Use fix-encoding-pragma pre-commit hook 2019-05-14 15:56:31 -07:00
Bruno Oliveira f1183c2422 Remove the 'issue' marker from test suite
It doesn't seem to add much value (why would one execute tests
based on that marker?), plus using the docstring for that
encourages one to write a more descriptive message about the test
2019-05-09 19:36:38 -03:00
Daniel Hahler 8b2fcf517c Merge master 2019-04-11 13:28:36 +02:00
Daniel Hahler 8011ff5bda Add _sys_snapshot fixture and use it with more tests 2019-04-05 11:55:23 +02:00
Daniel Hahler 899e74aa14 tests: harden test_immediate_initialiation_and_incremental_are_the_same 2019-04-05 11:55:23 +02:00
Daniel Hahler 66f743c45a Fix test_conftest when run via pytest-randomly 2019-04-05 11:55:23 +02:00
Zac-HD 00810b9b2a Register "issue" mark for self-tests 2019-03-31 14:22:30 +11:00
Paweł Stradomski 59e6fb94b5 Fix "ValueError: Plugin already registered" exceptions when running in build directories that symlink to actual source. 2019-02-07 02:05:22 +01:00
Daniel Hahler ce1cc3dddb _getconftestmodules: use functools.lru_cache
Also renames `_path2confmods` to `_dirpath2confmods` for clarity (it is
expected to be a dirpath in `_importconftest`).

Uses an explicit maxsize, since it appears to be only relevant for a
short period [1].

Removes the lru_cache on _getconftest_pathlist, which makes no
difference when caching _getconftestmodules, at least with the
performance test of 100x10 files (#4237).

1: https://github.com/pytest-dev/pytest/pull/4237#discussion_r228528007
2018-10-31 23:17:05 +01:00