summaryrefslogtreecommitdiff
path: root/src/_pytest/assertion
AgeCommit message (Collapse)Author
2020-12-15Some py.path.local -> pathlib.PathRan Benita
2020-11-14assertion/rewrite: write pyc's according to PEP-552 on Python>=3.7Ran Benita
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.
2020-10-31Add support to display field names in namedtuple diffs.Karthikeyan Singaravelan
2020-10-30assertion/util: remove unhelpful `type_fns` indirectionRan Benita
It doesn't serve any purpose that I am able to discern.
2020-10-19Drop support for EOL Python 3.5Hugo van Kemenade
2020-10-05py36+: com2annAnthony Sottile
2020-10-03py36+: pyupgrade: py36+Anthony Sottile
2020-10-03py36+: remove rexport of Path and PurePathAnthony Sottile
2020-10-03py36+: remove _pytest.compat.overloadAnthony Sottile
2020-10-02py36+: remove _pytest.compat.fspathAnthony Sottile
2020-10-02py36+: remove TYPE_CHECKING from _pytest.compatAnthony Sottile
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-09-27Bump attrs requirement from >=17.4.0 to >=19.2.0Ran Benita
This allows us to remove the `ATTRS_EQ_FIELD` thing which is causing some annoyance.
2020-09-12assertion/rewrite: fix internal error on collection error due to decorated ↵Ran Benita
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-12assertion/rewrite: rewrite condition to be easier to followRan Benita
2020-09-04Integrate warnings filtering directly into Config (#7700)Bruno Oliveira
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>
2020-08-04typing: set warn_unreachableRan Benita
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-01typing: set disallow_any_genericsRan Benita
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-01Format docstrings in a consistent styleRan Benita
2020-07-08assertion: improve diff output of recursive dataclass/attrsVlad-Radz
Co-authored-by: Vlad <uladzislau.radziuk@nordcloud.com>
2020-06-26Reduce calls of Node.ihookLukas Geiger
2020-06-12Fix some type errors around py.path.localRan Benita
These errors are found using a typed version of py.path.local.
2020-06-09Make dataclasses/attrs comparison recursive, fixes #4675ibriquem
2020-06-05Type annotate _pytest.assertionRan Benita
2020-06-05Type annotate _pytest._io.safereprRan Benita
2020-06-05Type annotate some more hooks & implsRan Benita
2020-06-05Type annotate some hookspecs & implsRan Benita
Annotate some "easy" arguments of hooks that repeat in a lot of internal plugins. Not all of the arguments are annotated fully for now.
2020-05-19Revisit some help texts with regard to newlinesDaniel Hahler
2020-04-09doc: internal: remove references to old "newinterpret" moduleDaniel Hahler
This has been merged into the (only) assertrewrite mode.
2020-03-27Change EnvironmentError, IOError to OSError - they are aliasesRan Benita
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
2020-03-27Merge pull request #6818 from blueyed/fix-assert-exc-upstreamRan Benita
assertion: rewrite: only catch EnvironmentError
2020-03-08tests: harden test_reprcompare_notin, factor out callop (#6764)Daniel Hahler
* tests: assertion: factor out `callop`, typing * tests: harden test_reprcompare_notin
2020-03-06Store AssertionState in config's store instead of attributeRan Benita
Part of moving away from ad-hoc attributes to using the config's store.
2020-02-29Mark AssertionRewritingHook as implementing importlib.abc.LoaderRan Benita
It implements the required methods. This is useful for typing but also a nice indicator.
2020-02-25assertion: rewrite: only catch EnvironmentErrorDaniel Hahler
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.
2020-02-14assertrepr_compare: provide more info (location) with exceptions (#6728)Daniel Hahler
2020-02-12Merge pull request #6673 from sscherfke/featuresBruno Oliveira
Reverse / fix meaning of "+/-" in error diffs
2020-02-11Merge remote-tracking branch 'upstream/master' into mmBruno Oliveira
Conflicts: src/_pytest/main.py src/_pytest/mark/structures.py src/_pytest/python.py testing/test_main.py testing/test_parseopt.py
2020-02-10Reverse / fix meaning of "+/-" in error diffsStefan Scherfke
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
2020-02-04assertion: save/restore hooks on item (#6646)Daniel Hahler
2020-01-31Merge branch 'master' into master-to-featuresRan Benita
2020-01-30typing: pytest_collectionDaniel Hahler
2020-01-14master: update mypy 0.740 -> 0.761Ran Benita
(cherry picked from commit 16ff9f591e38d1f2a79441f177130b1d89098c6e) (cherry picked from commit 4848bbdf9a4480ec85b520c6f3224256f1346679)
2020-01-10Merge master into featuresDaniel Hahler
2020-01-01Update mypy 0.750 -> 0.761Ran Benita
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.
2019-12-30minor: split doc with _early_rewrite_bailoutDaniel Hahler
2019-12-03Merge remote-tracking branch 'upstream/master' into mmBruno Oliveira
2019-12-02Update mypy 0.740 -> 0.750Ran Benita
Release notes: https://mypy-lang.blogspot.com/2019/11/mypy-0.html
2019-11-20minor: move internal _pformat_dispatch functionDaniel Hahler
2019-11-19Revert "A warning is now issued when assertions are made for `None`"Anthony Sottile
2019-11-18minor: visit_Assert: move setting of `negation` out of branchesDaniel Hahler