Age | Commit message (Collapse) | Author |
|
|
|
Python 3.7 changes the pyc format by adding a flags byte. Even though it
is not necessary for us to match it, it is nice to be able to read pyc
files we emit for debugging the rewriter.
Update our custom pyc files to use that format. We write flags==0
meaning we still use the mtime+size format rather the newer hash format.
|
|
|
|
It doesn't serve any purpose that I am able to discern.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
automated with:
```bash
git grep -l 'from .* import TYPE_CHECKING' |
xargs reorder-python-imports \
--application-directories .:src \
--remove-import 'from _pytest.compat import TYPE_CHECKING' \
--add-import 'from typing import TYPE_CHECKING'
```
|
|
This allows us to remove the `ATTRS_EQ_FIELD` thing which is causing
some annoyance.
|
|
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.
|
|
|
|
Warnings are a central part of Python, so much that Python itself has
command-line and environtment variables to handle warnings.
By moving the concept of warning handling into Config, it becomes natural to
filter warnings issued as early as possible, even before the "_pytest.warnings"
plugin is given a chance to spring into action. This also avoids the weird
coupling between config and the warnings plugin that was required before.
Fix #6681
Fix #2891
Fix #7620
Fix #7626
Close #7649
Co-authored-by: Ran Benita <ran@unusedvar.com>
|
|
This makes mypy raise an error whenever it detects code which is
statically unreachable, e.g.
x: int
if isinstance(x, str):
... # Statement is unreachable [unreachable]
This is really neat and finds quite a few logic and typing bugs.
Sometimes the code is intentionally unreachable in terms of types, e.g.
raising TypeError when a function is given an argument with a wrong
type. In these cases a `type: ignore[unreachable]` is needed, but I
think it's a nice code hint.
|
|
This prevents referring to a generic type without filling in its generic
type parameters.
The FixtureDef typing might need some more refining in the future.
|
|
|
|
Co-authored-by: Vlad <uladzislau.radziuk@nordcloud.com>
|
|
|
|
These errors are found using a typed version of py.path.local.
|
|
|
|
|
|
|
|
|
|
Annotate some "easy" arguments of hooks that repeat in a lot of internal
plugins.
Not all of the arguments are annotated fully for now.
|
|
|
|
This has been merged into the (only) assertrewrite mode.
|
|
Since Python 3.3, these are aliases for OSError:
https://docs.python.org/3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy
|
|
assertion: rewrite: only catch EnvironmentError
|
|
* tests: assertion: factor out `callop`, typing
* tests: harden test_reprcompare_notin
|
|
Part of moving away from ad-hoc attributes to using the config's store.
|
|
It implements the required methods. This is useful for typing but also a
nice indicator.
|
|
This was changed unintentionally in 45c4a8fb3 (pytest 5.3.0), but only
EnvironmentErrors might have `errno`.
Since that is not really guaranteed and it is good to have more
information this uses the string representation of the exc in the trace
message.
|
|
|
|
Reverse / fix meaning of "+/-" in error diffs
|
|
Conflicts:
src/_pytest/main.py
src/_pytest/mark/structures.py
src/_pytest/python.py
testing/test_main.py
testing/test_parseopt.py
|
|
The convention is "assert result is expected". Pytest's error diffs now
reflect this. "-" means that sth. expected is missing in the result and
"+" means that there are unexpected extras in the result.
Fixes: #3333
|
|
|
|
|
|
|
|
(cherry picked from commit 16ff9f591e38d1f2a79441f177130b1d89098c6e)
(cherry picked from commit 4848bbdf9a4480ec85b520c6f3224256f1346679)
|
|
|
|
This fixes some type: ignores due to typeshed update.
Newer mypy seem to ignore unannotated functions better, so add a few
minor annotations so that existing correct type:ignores make sense.
|
|
|
|
|
|
Release notes:
https://mypy-lang.blogspot.com/2019/11/mypy-0.html
|
|
|
|
|
|
|