Anthony Sottile
bfadd4060e
py36+: from typing import Type: no longer need guard
2020-10-02 19:50:10 -07:00
Anthony Sottile
ced0a52a87
Merge pull request #7837 from asottile/py36_union_pattern_match
...
py36+: remove workaround for Union[Pattern/Match] bug
2020-10-02 19:47:50 -07:00
Anthony Sottile
e622cb7c41
py36+: remove workaround for Union[Pattern/Match] bug
2020-10-02 15:06:02 -07:00
Anthony Sottile
a238d1f37d
py36+: remove TYPE_CHECKING from _pytest.compat
...
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'
```
2020-10-02 15:03:24 -07:00
Ran Benita
32bb8f3a63
Bump attrs requirement from >=17.4.0 to >=19.2.0
...
This allows us to remove the `ATTRS_EQ_FIELD` thing which is causing
some annoyance.
2020-09-27 13:17:59 +03:00
Ran Benita
a99ca879e7
Mark some public and to-be-public classes as `@final`
...
This indicates at least for people using type checkers that these
classes are not designed for inheritance and we make no stability
guarantees regarding inheritance of them.
Currently this doesn't show up in the docs. Sphinx does actually support
`@final`, however it only works when imported directly from `typing`,
while we import from `_pytest.compat`.
In the future there might also be a `@sealed` decorator which would
cover some more cases.
2020-09-22 12:40:40 +03:00
Anthony Sottile
96a17b1683
Fix INTERNALERROR when accessing locals / globals with faulty `exec`
2020-09-11 18:13:48 -07:00
Bruno Oliveira
9f672c85c5
Fix handle of exceptions in ReprEntry with tb=line
...
Fix #7707
2020-09-03 07:44:45 -03:00
Ran Benita
f28af14457
Don't use NotImplementedError in `@overload`s
...
We used it as a shortcut for avoiding coverage, but pylint has a special
interpretation of it as an abstract method which we don't want.
2020-08-14 13:54:46 +03:00
Ran Benita
f8c4e038fd
Replace some usages of py.path.local
2020-08-06 18:46:17 +03:00
Ran Benita
9ab14c6d9c
typing: set warn_unreachable
...
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.
2020-08-04 09:59:46 +03:00
Ran Benita
be656dd4e4
typing: set disallow_any_generics
...
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.
2020-08-01 20:39:15 +03:00
Ran Benita
0242de4f56
Format docstrings in a consistent style
2020-08-01 17:14:37 +03:00
Zac Hatfield-Dodds
3a060b77e8
Revert change to traceback repr ( #7535 )
...
* Revert change to traceback repr
* Add test and changelog entry
* Restore *exact* prev output
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-07-24 13:30:38 +02:00
Lewis Cowles
71ab6236a1
Clearer guidance on pytest.raise(match=...) failure ( #7499 )
2020-07-15 22:26:47 +03:00
Ran Benita
c8676002a7
code/code: remove redundant __ne__ implementation
...
This implementation is the default when __eq__ is implemented.
2020-07-10 13:08:56 +03:00
Ran Benita
85ef2bf698
code/code: remove Frame.exec_() method
...
Not used.
2020-07-10 13:08:56 +03:00
Ran Benita
c3864bc12b
code/code: remove Frame.is_true() method
...
Really odd one, let's just inline it.
2020-07-10 13:08:56 +03:00
Ran Benita
77f3cb4baa
code/code: type annotations & doc cleanups
2020-07-10 13:08:56 +03:00
Ran Benita
fb2640b82f
Stop using ExceptionInfo.errisinstance internally
...
It does the same as a simple isinstance check, but adds a little layer
of obscurity on top, which the type checker can't penetrate.
2020-07-10 13:08:48 +03:00
Ran Benita
4655b79985
config: improve typing
2020-06-22 16:39:14 +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
Ran Benita
0256cb3aae
hookspec: type annotate pytest_internalerror
...
Also switch to using ExceptionRepr instead of
`Union[ReprExceptionInfo, ExceptionChainRepr]`
which is somewhat annoying and less future proof.
2020-06-12 17:34:31 +03:00
Ran Benita
2b05faff0a
Improve types around repr_failure()
2020-06-05 11:34:20 +03:00
Ran Benita
54ad048be7
Enable check_untyped_defs mypy option for testing/ too
2020-06-05 11:34:20 +03:00
Katarzyna Król
94c7b8b47c
Issue 1316 - longrepr is a string when pytrace=False ( #7100 )
2020-05-30 14:10:58 +03:00
Ran Benita
2ee90887b7
code: remove last usage of py.error
...
`str(self.path)` can't raise at all, so it can just be removed.
2020-05-28 12:12:10 +03:00
Ran Benita
23c9856857
Remove no longer needed noqa's
2020-05-12 09:29:47 +03:00
Ran Benita
59a12e9ab3
Replace bare `except`s with `except BaseException`
...
Mostly I wanted to remove uses of `noqa`.
In Python 3 the two are the same.
2020-05-12 09:29:47 +03:00
Ran Benita
69143fe5b0
code: fix import cycles between code.py and source.py
...
These two files were really intertwined. Make it so code.py depends on
source.py without a reverse dependency.
No functional changes.
2020-05-06 11:01:32 +03:00
Daniel Hahler
20f6331afd
Fix TerminalRepr instances to be hashable ( #6988 )
...
pytest-xdist assumes `ExceptionChainRepr` is hashable.
Fixes https://github.com/pytest-dev/pytest/issues/6925 .
Fixes https://github.com/pytest-dev/pytest-xdist/issues/515 .
2020-04-03 00:56:53 +02:00
Bruno Oliveira
429a28eca0
Merge pull request #6782 from nicoddemus/code-highlight-followup
...
Assorted improvements following up #6658
2020-03-27 08:58:50 -03:00
Daniel Hahler
b11bfa106c
Use attrs with all Repr classes ( #6739 )
...
Co-authored-by: Ran Benita <ran234@gmail.com>
2020-03-03 21:53:28 +01:00
Daniel Hahler
2be06ba67e
Improve doc/typing/message for `ExceptionInfo.match` ( #6776 )
2020-02-21 16:41:57 +01:00
Bruno Oliveira
c91abe48ba
Assorted improvements following up #6658
2020-02-20 18:51:41 -03:00
Daniel Hahler
9631b3c166
reports: use attr.asdict with serialize_repr_{crash,traceback} ( #6732 )
...
* Turn ReprTraceback into attrs class
* Use attr.asdict with serialize_repr_{crash,traceback}
* Turn ReprFileLocation into attrs class, convert py.path.local
2020-02-14 19:39:34 +01:00
Bruno Oliveira
4209ad6fca
Use code highlighting if pygments is installed ( #6658 )
...
* Use code highlighting if pygments is installed
* Use colorama constants instead of bare ascii codes
Could not find the exact equivalent of 'hl-reset' code using colorama
constants though.
* Refactor ASCII color handling into a fixture
* Revert back to using explicit color codes
* In Python 3.5 skip rest of tests that require ordered markup in colored output
2020-02-12 08:32:37 -03:00
Bruno Oliveira
78baa7b575
Merge remote-tracking branch 'upstream/master' into mm
...
Conflicts:
src/_pytest/main.py
src/_pytest/mark/structures.py
src/_pytest/python.py
testing/test_main.py
testing/test_parseopt.py
2020-02-11 19:22:28 -03:00
Daniel Hahler
61f2a26675
Code/getfslineno: keep empty co_filename
...
Previously this would be turned via `py.path.local("")` into the current
working directory.
This appears to be what `fspath = fn and py.path.local(fn) or None`
tries to avoid in `getfslineno`'s `TypeError` handling already, if
`Code` would raise it.
2020-02-03 19:09:08 +01:00
Daniel Hahler
55e5817570
Merge master into features
2020-01-29 03:07:35 +01:00
Daniel Hahler
12c5a6af64
typing: fix Code.path
...
Fixes:
> src/_pytest/_code/code.py:83: error: Incompatible types in assignment
> (expression has type "str", variable has type "local") [assignment]
2020-01-28 01:49:45 +01:00
Daniel Hahler
09bdbffbde
Merge master into features
...
Conflicts:
src/_pytest/_code/code.py
src/_pytest/main.py
2020-01-24 23:44:50 +01:00
Daniel Hahler
03bc8aba4e
config: typing for create_terminal_writer, re-export TerminalWriter
...
This also imports `TerminalWriter` explicitly via `_pytest._io`,
allowing for easier extending / replacing it.
2020-01-23 14:09:37 +01: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
7ee27fedee
doc: fix Code.path: might return str
2020-01-21 19:46:43 +01:00
Ran Benita
0c247be769
Add a few missing type annotations in _pytest._code
...
These are more "dirty" than the previous batch (that's why they were
left out). The trouble is that `compile` can return either a code object
or an AST depending on a flag, so we need to add an overload to make the
common case Union free. But it's still worthwhile.
2020-01-19 19:39:14 +02:00
Daniel Hahler
32b62f770f
Merge pull request #6509 from blueyed/typing-minor
...
typing: minor improvements
2020-01-19 11:33:41 +01:00
Daniel Hahler
09e9a01df3
typing: fix _TracebackStyle: add "line"
2020-01-19 11:22:47 +01:00
Daniel Hahler
5c445b05e7
typing: py.io.TerminalWriter for tw arguments
2020-01-19 11:21:16 +01:00
Daniel Hahler
1667cf3350
Merge pull request #6384 from pv/showlocals-short
...
Make --showlocals work together with --tb=short
Fixes https://github.com/pytest-dev/pytest/issues/494
Ref: https://github.com/pytest-dev/pytest/issues/1715
2020-01-16 22:04:14 +01:00