Commit Graph

152 Commits

Author SHA1 Message Date
Anthony Sottile fb1d550aac py36+: remove rexport of Path and PurePath 2020-10-03 12:16:52 -07:00
Anthony Sottile 1f57fb079d py36+: remove _pytest.compat.MODULE_NOT_FOUND_ERROR 2020-10-02 15:02:45 -07:00
Ran Benita d18cb961cf assertion/rewrite: fix internal error on collection error due to decorated function
For decorated functions, the lineno of the FunctionDef AST node points
to the `def` line, not to the first decorator line. On the other hand,
in code objects, the `co_firstlineno` points to the first decorator
line.

Assertion rewriting inserts some imports to code it rewrites. The
imports are inserted at the lineno of the first statement in the AST. In
turn, the code object compiled from the rewritten AST uses the lineno of
the first statement (which is the first inserted import).

This means that given a module like this,

```py
@foo
@bar
def baz(): pass
```

the lineno of the code object without assertion rewriting
(`--assertion=plain`) is 1, but with assertion rewriting it is 3.

And *this* causes some issues for the exception repr when e.g. the
decorator line is invalid and raises during collection. The code becomes
confused and crashes with

INTERNALERROR>   File "_pytest/_code/code.py", line 638, in get_source
INTERNALERROR>     lines.append(space_prefix + source.lines[line_index].strip())
INTERNALERROR> IndexError: list index out of range

Fix it by special casing decorators. Maybe there are other cases like
this but off hand I can't think of another Python construct where the
lineno of the item would be after its first line, and this is the only
such issue we have had reported.
2020-09-12 23:05:08 +03:00
Bruno Oliveira 52b0cc4f19 Remove broken pytest_collect_directory hook 2020-08-19 08:14:25 -03:00
Bruno Oliveira b426bb3443 Refactor Session._parsearg into a separate function for testing 2020-08-15 13:23:55 -03:00
Bruno Oliveira 2213016e40 Fix Module.name from full path without drive letter
Fix #7628
2020-08-15 09:39:14 -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 7ec6401ffa
Change pytest deprecation warnings into errors for 6.0 release (#7362)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-07-22 21:36:51 -03:00
Ran Benita a2f021b6f3 Remove no longer needed `noqa: F821` uses
Not needed since pyflakes 2.2.0.
2020-07-10 13:08:56 +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 54ad048be7 Enable check_untyped_defs mypy option for testing/ too 2020-06-05 11:34:20 +03:00
Bruno Oliveira c5b367b4f4 Package.name now contains only basname of the package
Previously it contained the entire path, which made '-k' match
against any name in the full path of the package.

Fix #7040
2020-05-16 15:04:07 -03:00
Bruno Oliveira 7f5978c34c Allow File.from_parent to forward custom parameters to the constructor 2020-05-01 11:00:52 -03:00
Daniel Hahler 4fd2623c12
tests: fix TypeErrors (#7038)
* tests: fix TypeError with test_mark_closest

It fails when trying to run it actually:

> TypeError: test_has_inherited() takes 0 positional arguments but 1 was given

* Fix testing/test_collection.py::TestCollector::test_getparent
2020-04-08 18:11:04 +02:00
Ronny Pfannschmidt 9fd71d6fe0
fix #571: deprecate pytest_collect_directory as ... (#6847)
Deprecate pytest_collect_directory

Fix #571

Co-authored-by: Daniel Hahler <github@thequod.de>
2020-03-03 18:58:14 -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 30922ee694 Merge master into features 2020-01-28 01:40:14 +01:00
Daniel Hahler ad0f4f0ac0 tests: cover collect_by_name with non-existing 2020-01-28 00:41:46 +01:00
Ran Benita dd5c2b22bd Refactor Session._initialparts to have a more explicit type
Previously, _initialparts was a list whose first item was a
`py.path.local` and the rest were `str`s. This is not something that
mypy is capable of modeling. The type `List[Union[str, py.path.local]]`
is too broad and would require asserts for every access.

Instead, make each item a `Tuple[py.path.local, List[str]]`. This way
the structure is clear and the types are accurate.

To make sure any users who might have been accessing this (private)
field will not break silently, change the name to _initial_parts.
2020-01-25 13:57:49 +02:00
Bruno Oliveira 93b74d28d2 Merge remote-tracking branch 'upstream/master' into mm
Conflicts:
 * 	src/_pytest/_code/code.py
 * 	src/_pytest/main.py
 * 	testing/python/metafunc.py
 * 	testing/test_parseopt.py
 * 	testing/test_pytester.py
2020-01-22 11:03:45 -03:00
Daniel Hahler 5049e25a6a tests: cleanup unused fixtures 2020-01-16 21:12:48 +01:00
Christoph Buelter a326fa22c6 Add a failing test to ensure not everything matches by accident 2019-12-05 17:02:48 +01:00
Christoph Buelter e24b6b0388 Change -k EXPRESSION matching to be case-insensitive 2019-12-05 14:03:10 +01:00
Ronny Pfannschmidt c99c7d0f95 deprecate direct node construction and introduce Node.from_parent 2019-11-23 21:54:11 +01:00
Bruno Oliveira 21622d0df4 Merge remote-tracking branch 'upstream/master' into release-5.3.0 2019-11-19 12:42:11 -03:00
林玮 5d5f480979 Hardening an existing test for demonstrating this change. 2019-11-18 23:46:38 +08:00
Anthony Sottile a2d48332fc
Merge pull request #6201 from asottile/mm
Merge master into features
2019-11-17 11:30:51 -08:00
Daniel Hahler 54a954514b re-run black 2019-11-16 18:55:32 +01:00
Anthony Sottile cc78444c30 Merge remote-tracking branch 'origin/master' into mm 2019-11-15 15:26:57 -08:00
Anthony Sottile 4e0f99260d Add regression tests for __init__.py breakage 2019-11-15 13:19:31 -08:00
Daniel Hahler b06f33f474 terminal: report ``session.shouldfail`` reason (``-x``)
Via https://github.com/blueyed/pytest/pull/108.
2019-11-13 16:18:41 +01:00
NNRepos 4946cc8282 Add --co option to collect-only
Fix #5845
2019-11-07 17:50:27 -03:00
MarcoGorelli d863c30c74 Fix plurality mismatch for and in pytest terminal summary 2019-10-27 15:16:24 +00:00
Bruno Oliveira 47c2091ecd Use new no-match functions to replace previous idiom 2019-10-06 18:05:24 -03:00
Daniel Hahler 198fcd8a6f Fix RuntimeError when trying to collect package with "__init__.py" only
Fixes https://github.com/pytest-dev/pytest/issues/4344.
2019-08-05 17:52:21 +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
Bruno Oliveira 4d49ba6529 Drop Python 2.7 and 3.4 support
* Update setup.py requires and classifiers
* Drop Python 2.7 and 3.4 from CI
* Update docs dropping 2.7 and 3.4 support
* Fix mock imports and remove tests related to pypi's mock module
* Add py27 and 34 support docs to the sidebar
* Remove usage of six from tmpdir
* Remove six.PY* code blocks
* Remove sys.version_info related code
* Cleanup compat
* Remove obsolete safe_str
* Remove obsolete __unicode__ methods
* Remove compat.PY35 and compat.PY36: not really needed anymore
* Remove unused UNICODE_TYPES
* Remove Jython specific code
* Remove some Python 2 references from docs

Related to #5275
2019-06-02 14:39:11 -03:00
Anthony Sottile dc75b6af47 Use fix-encoding-pragma pre-commit hook 2019-05-14 15:56:31 -07:00
Bruno Oliveira 02188e399d
Merge pull request #4987 from blueyed/collect-tbstyle-repr_failure
CollectError.repr_failure: honor explicit tbstyle option
2019-03-26 18:37:49 -03:00
Daniel Hahler de44293d59 CollectError.repr_failure: honor explicit tbstyle option 2019-03-24 11:24:19 +01:00
Daniel Hahler 08f3b02dfc tests: fnmatch_lines: use list
For strings fnmatch_lines converts it into a Source objects, splitted on
newlines.  This is not necessary here, and it is more consistent to use
lists here in the first place.
2019-03-23 11:36:18 +01:00
Miro Hrončok d32ab6029f Fix pytest tests invocation with custom PYTHONPATH
Fixes https://github.com/pytest-dev/pytest/issues/4913

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2019-03-12 17:31:42 +01:00
Bruno Oliveira 0395996756 Merge remote-tracking branch 'upstream/master' into release-4.3.0 2019-02-16 14:06:51 +00:00
Daniel Hahler 407d4a0cf0 collect: python: fix `AssertionError` with broken symlinks
Fixes https://github.com/pytest-dev/pytest/issues/4782.
2019-02-14 00:18:14 +01:00
Daniel Hahler 7b91952645 Merge master into features
Conflicts:
	tox.ini
2019-02-13 17:58:16 +01:00