Ran Benita
83e18776f6
Merge pull request #6818 from blueyed/fix-assert-exc-upstream
...
assertion: rewrite: only catch EnvironmentError
2020-03-27 18:33:17 +03:00
Ran Benita
678d65f051
Store AssertionState in config's store instead of attribute
...
Part of moving away from ad-hoc attributes to using the config's store.
2020-03-06 11:27:01 +02:00
Ran Benita
2f60548e08
Mark AssertionRewritingHook as implementing importlib.abc.Loader
...
It implements the required methods. This is useful for typing but also a
nice indicator.
2020-02-29 16:55:56 +02:00
Daniel Hahler
eac933acde
assertion: rewrite: only catch EnvironmentError
...
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-25 17:29:30 +01:00
Ran Benita
090e260517
master: update mypy 0.740 -> 0.761
...
(cherry picked from commit 16ff9f591e
)
(cherry picked from commit 4848bbdf9a
)
2020-01-14 06:31:41 +01:00
Daniel Hahler
a5863ca760
minor: split doc with _early_rewrite_bailout
2019-12-30 09:41:36 +01:00
Anthony Sottile
faea273c93
Revert "A warning is now issued when assertions are made for `None`"
2019-11-19 08:24:08 -08:00
Daniel Hahler
f38f2d402e
minor: visit_Assert: move setting of `negation` out of branches
2019-11-18 23:21:00 +01:00
Ran Benita
f760356578
A few linting fixes
...
Add some Python 3.8 type: ignores; all are already fixed in the next
mypy release, so can be removed once we upgrade.
Also move some flake8 ignores which seem to have changed places.
2019-11-16 17:22:06 +02: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
Daniel Hahler
45c4a8fb3d
Use atomicrewrites only on Windows
...
Fixes https://github.com/pytest-dev/pytest/issues/6147
2019-11-07 20:57:45 +01:00
Bruno Oliveira
6f20b4b014
Introduce compat.fspath
2019-10-26 10:37:44 -03:00
Bruno Oliveira
f93f284356
Support sys.pycache_prefix on py38
...
Fix #4730
2019-10-26 10:17:21 -03:00
Ran Benita
1cc1ac5183
Remove some type: ignores fixed in typeshed
2019-10-23 14:47:56 +03:00
Bruno Oliveira
c28e428249
Merge remote-tracking branch 'upstream/master' into mm
2019-08-26 20:00:30 -03:00
Daniel Hahler
05bfe73cf9
Fix wrong location of assertion error with coverage.py
...
Reverts using-constant part from 39ba99613
.
Fixes https://github.com/pytest-dev/pytest/issues/5754 .
2019-08-17 21:34:13 +02:00
Ran Benita
7259c453d6
Fix some check_untyped_defs = True mypy warnings
2019-08-16 10:41:57 +03:00
Ran Benita
28761c8da1
Have AssertionRewritingHook derive from importlib.abc.MetaPathFinder
...
This is nice for self-documentation, and is the type required by mypy
for adding to sys.meta_path.
2019-08-16 10:41:52 +03:00
Daniel Hahler
39ba996133
assertion.rewrite: use ast.NameConstant(None) directly
...
`ast.parse("None")` was added/used in 3e6f1fa2d
for differences between
Python 2/3, but we do not support py2 anymore.
2019-08-12 07:50:52 +02:00
Bruno Oliveira
d3e1907899
Use OSError subclasses instead of handling errno
2019-08-02 14:17:46 -03:00
Ran Benita
89dfde9535
Add rudimentary mypy type checking
...
Add a very lax mypy configuration, add it to tox -e linting, and
fix/ignore the few errors that come up. The idea is to get it running
before diving in too much.
This enables:
- Progressively adding type annotations and enabling more strict
options, which will improve the codebase (IMO).
- Annotating the public API in-line, and eventually exposing it to
library users who use type checkers (with a py.typed file).
Though, none of this is done yet.
Refs https://github.com/pytest-dev/pytest/issues/3342 .
2019-07-09 12:12:07 -07:00
Anthony Sottile
7ee244476a
Remove astor and reproduce the original assertion expression
2019-06-28 13:38:52 -07:00
Bruno Oliveira
1be49e713a
Remove py<35 compatibility code from rewrite.py
2019-06-26 21:44:10 -03:00
Bruno Oliveira
629eb3ec6a
Move formatting variables under the "has impls" if
...
Small optimization, move the generation of the intermediate
formatting variables inside the 'if _check_if_assertion_pass_impl():'
block.
2019-06-26 19:26:12 -03:00
Bruno Oliveira
fcbe66feba
Restore proper handling of '%' in assertion messages
2019-06-26 18:51:27 -03:00
Victor Maryama
6854ff2acc
Fixed import order pep8.
2019-06-26 19:05:17 +02:00
Victor Maryama
53234bf613
Added config back to AssertionWriter and fixed typo in check_if_assertion_pass_impl function call.
2019-06-26 19:00:31 +02:00
Victor Maryama
6f851e6cbb
Merge remote-tracking branch 'upstream/master' into features-assertion-pass-hook-master
...
# Conflicts:
# src/_pytest/assertion/rewrite.py
2019-06-26 18:12:56 +02:00
Victor Maryama
9a34d88c8d
Explanation variables only defined if failed or passed with plugins implementing the hook.
2019-06-26 18:10:16 +02:00
Victor Maryama
f755ff6af1
Black formatting.
2019-06-26 18:10:16 +02:00
Victor Maryama
d638da5821
Using ini-file option instead of cmd option.
2019-06-26 18:10:16 +02:00
Bruno Oliveira
6a2d844c5d
Fix typo replace `circuting` with `circuiting`. ( #5497 )
...
Fix typo replace `circuting` with `circuiting`.
2019-06-26 11:09:22 -03:00
Tim Gates
fdb6e35b1b
Fix typo replace `circuting` with `circuiting`.
2019-06-26 20:23:35 +10:00
Victor Maryama
7efdd5063b
Update src/_pytest/assertion/rewrite.py
...
Co-Authored-By: Bruno Oliveira <nicoddemus@gmail.com>
2019-06-26 10:50:27 +02:00
Bruno Oliveira
aaf40314d1
Do not attempt to rewrite non-source files ( #5490 )
...
Do not attempt to rewrite non-source files
2019-06-25 20:43:23 -03:00
Victor Maryama
4db5488ed8
Now dependent on command line option.
2019-06-25 19:49:05 +02:00
Anthony Sottile
b991810f32
Do not attempt to rewrite non-source files
2019-06-25 08:00:20 -07:00
Victor Maryama
f8c9a7b86d
Formatting and removed py2 support.
2019-06-25 10:35:42 +02:00
Bruno Oliveira
f43fb13179
Include pytest version in the cached pyc tags
...
Fix #1671
2019-06-24 20:37:07 -03:00
Anthony Sottile
4cd08f9b52
Switch from deprecated imp to importlib
2019-06-24 09:48:38 -07:00
Victor Maryama
52e695b329
Removed debug code.
2019-06-24 17:47:48 +02:00
Victor Maryama
9a89783fbb
Assertion passed hook
2019-06-24 16:09:39 +02:00
Anthony Sottile
be2be040f9
Clean up u' prefixes and py2 bytes conversions
2019-06-04 17:50:34 -07:00
Anthony Sottile
1b381d5277
Revert "Unroll calls to any #5062 ( #5103 )"
...
This reverts commit 2b9ca34280
, reversing
changes made to 0a57124063
.
2019-06-03 08:42:03 -07:00
Anthony Sottile
2125d04501
Revert "Fix all() unroll for non-generators/non-list comprehensions ( #5360 )"
...
This reverts commit 733f43b02e
, reversing
changes made to e4fe41ebb7
.
2019-06-03 08:42:03 -07:00
Anthony Sottile
5dcf85c17e
manual: remove dependence on six
2019-06-03 12:08:02 -03: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
Bruno Oliveira
acdf30a523
Fix all() unroll for non-generators/non-list comprehensions
...
Fix #5358
2019-06-02 12:12:14 -03:00
Daniel Hahler
e032904413
Merge master into features
2019-05-28 01:46:16 +02:00
Bruno Oliveira
2b9ca34280
Unroll calls to any #5062 ( #5103 )
...
Unroll calls to any #5062
2019-05-27 20:17:44 -03:00
Anthony Sottile
13f02af97d
Switch to importlib-metadata
2019-05-27 13:24:08 -07:00
Tomer Keren
22d91a3c3a
Unroll calls to all on python 2
2019-05-25 19:34:08 +03:00
Tomer Keren
322a0f0a33
Fix mention of issue #5062 in docstrings
2019-05-25 19:34:08 +03:00
Tomer Keren
58149459a5
Mark visit_all as a private method
2019-05-25 19:34:08 +03:00
Tomer Keren
437d6452c1
Expand list comprehensions as well
2019-05-25 19:34:08 +03:00
Tomer Keren
e37ff3042e
Check calls to all only if it's a name and not an attribute
2019-05-25 19:34:08 +03:00
Tomer Keren
470e686a70
Rewrite unrolled assertion with a new rewriter,correctly append the unrolled for loop
2019-05-25 19:34:08 +03:00
Tomer Keren
765f75a8f1
Replace asserts of `any` with an assert in a for
2019-05-25 19:34:08 +03:00
Bruno Oliveira
66f20b6f5e
Fix invalid Python file encoding "utf8" ( #5252 )
...
Fix invalid Python file encoding "utf8"
2019-05-23 20:24:23 -03:00
Daniel Hahler
93fd9debe3
Allow disabling of python plugin
...
Fixes https://github.com/pytest-dev/pytest/issues/5277 .
2019-05-17 18:17:14 +02:00
Anthony Sottile
dc75b6af47
Use fix-encoding-pragma pre-commit hook
2019-05-14 15:56:31 -07:00
Bruno Oliveira
ccf6c3cb46
Merge remote-tracking branch 'upstream/master' into merge-master-into-features
2019-05-09 19:22:40 -03:00
Anthony Sottile
d1a48ad68f
Use exec directly
2019-05-06 23:07:39 -07:00
Bruno Oliveira
53cd7fd2ea
Introduce new warning subclasses
...
Fix #5177
2019-04-28 10:38:25 -03:00
Daniel Hahler
adb8edbae1
assertion rewriting: use actual helper name
...
This makes it easier / possible to grep.
2019-04-17 14:41:34 +02:00
Daniel Hahler
7afe17740f
Merge master into features
2019-03-15 00:52:12 +01:00
Bruno Oliveira
44cb51010c
Improve CHANGELOG and code comment
2019-03-13 18:52:30 -03:00
Bernhard M. Wiedemann
489c61a22d
Allow tests to pass after 2038
...
without this change, the python-apache-libcloud tests failed
in the year 2039 with
fp.write(struct.pack("<ll", mtime, size))
E error: 'l' format requires -2147483648 <= number <= 2147483647
2019-03-10 05:22:21 +01:00
Daniel Hahler
9cb71af9e5
_pytest.assertion.rewrite: move _format_explanation import
2019-03-01 14:13:28 +01:00
Bruno Oliveira
ade5f2c8c5
Merge remote-tracking branch 'upstream/master' into merge-master-into-features
2019-01-29 19:36:56 -02:00
Anthony Sottile
0c6ca0da62
Fix usages of py.io.saferepr
2019-01-20 16:36:23 -08:00
Anthony Sottile
ec5e279f93
Remove and ban use of py.builtin
2019-01-20 11:59:48 -08:00
Daniel Hahler
1a358df998
Merge master into features
2019-01-14 17:15:39 +01:00
Anthony Sottile
16546b7342
Remove some dead code
...
- I wrote a thing: https://github.com/asottile/dead
- wanted to try it out, there's lots of false positives and I didn't look
through all the things it pointed out but here's some
2019-01-13 20:41:30 -08:00
Anton Lodder
3241fc3103
Don't fail if hasattr fails when rewriting assertions
...
When rewriting assertions, pytest makes a call to
`__name__` on each object in a comparision. If one of
the objects has reimplemented `__getattr__`, they could
fail trying to fetch `__name__` with an error other than
`AttributeError`, which is what `hasattr` catches.
In this case, the stack trace for the failed `__getattr__`
call will show up in the pytest output, even though
it isn't related to the test failing.
This change fixes that by catching exceptions
that `hasattr` throws.
2019-01-10 20:45:15 -05:00
Bruno Oliveira
fd48cd57f9
Remove config.warn, Node.warn; pytest_logwarning issues a warning when implemented
...
Fix #3078
2018-12-14 12:50:18 -02:00
Daniel Hahler
5ebacc49c6
Harden tests, fix doc/msg
2018-12-05 19:22:44 +01:00
Tomer Keren
8fd60483ef
Don't insert warnings when not in a module
2018-12-05 19:49:54 +02:00
Tomer Keren
7a7ad0c120
Shorten docstring for warn_about_none_ast
2018-12-05 17:47:34 +02:00
Tomer Keren
41031fce2f
Address code review
2018-12-05 17:18:57 +02:00
Tomer Keren
e1e4b226c6
👌 Address code review
...
Edited the changelog for extra clarity, and to fire off auto-formatting
Oddly enough, keeping `filename='{filename!r}'` caused an error while
collecting tests, but getting rid of the single ticks fixed it
Hopefully closes #3191
2018-12-05 10:52:12 +02:00
Tomer Keren
3e6f1fa2db
Simplify warning creation by using ast.parse
...
in py2 it's a ast.Name where in py3 it's a ast.NamedConstant
Fixes namespace by using import from
2018-12-05 10:42:05 +02:00
Tomer Keren
59a11b6a5d
Check for 'assert None' and warn appropriately
...
🐛 Fix warn ast bugs
🐛 Fix inner-ast imports by using importFrom
Alternetavly ast_call_helper could be retooled to use ast.attribute(...)
2018-12-05 10:41:42 +02:00
Bruno Oliveira
aa765cf8c2
Adjust stacklevel of "config" warnings
...
Related to #4439
2018-11-22 14:44:01 -02:00
Anthony Sottile
690a63b921
Fix assertion rewriting involving Starred + side-effects
2018-11-17 10:42:51 -08:00
Anthony Sottile
2368fbb63c
Apply reorder-python-imports to all files
2018-10-25 00:01:29 -07:00
Anthony Sottile
cb39bd0651
Fixes for flake8 master
2018-10-22 08:50:00 -07:00
Bruno Oliveira
9646a1cd7a
Merge remote-tracking branch 'upstream/master' into merge-master-into-features
2018-10-15 12:55:28 -03:00
Anthony Sottile
2e42d937dc
Display the filename when encountering `SyntaxWarning`.
...
```console
$ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd ..
. [100%]
=============================== warnings summary ===============================
<unknown>:2: DeprecationWarning: invalid escape sequence \.
-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 passed, 1 warnings in 0.01 seconds
```
```console
$ cd t && rm -rf __pycache__ && pytest t.py -q -c /dev/null; cd ..
. [100%]
=============================== warnings summary ===============================
/tmp/pytest/t/t.py:2: DeprecationWarning: invalid escape sequence \.
'\.wat'
-- Docs: https://docs.pytest.org/en/latest/warnings.html
1 passed, 1 warnings in 0.01 seconds
```
2018-10-14 16:11:47 -07:00
Ronny Pfannschmidt
2831cb9ab5
unify paths.py and pathlib.py
2018-10-11 07:15:09 +02:00
Ronny Pfannschmidt
85cc9b8f12
move all the things into _pytest.pathlib
2018-10-11 07:15:08 +02:00
iwanb
c61ff31ffa
Fix #3539 : reload module with assertion rewrite import hook
2018-09-23 13:05:55 +02:00
Anthony Sottile
7122fa5613
Fix UnicodeDecodeError in assertion with mixed non-ascii bytes repr + text
2018-09-19 20:24:00 -07:00
Bruno Oliveira
37d2469266
Use a PurePath instance to do matching against patterns in assertion rewrite
...
This way we don't need to have real file system path, which prevents the
original #3973 bug.
2018-09-17 20:29:09 -03:00
Bruno Oliveira
1df6d28080
Fix assertion rewriter crash if cwd changes mid-testing
...
Unfortunately we need to get a `py.path.local` object to perform the fnmatch
operation, it is different from the standard `fnmatch` module because it
implements its own custom logic. So we need to use `py.path` to perform
the fnmatch for backward compatibility reasons.
Ideally we should be able to use a "pure path" in `pathlib` terms (a path
not bound to the file system), but we don't have those in pylib.
Fix #3973
2018-09-17 20:04:44 -03:00
Bruno Oliveira
69b34f7658
Merge remote-tracking branch 'upstream/master' into release-3.8.0
2018-09-05 18:02:02 -03:00
Bruno Oliveira
d3ca739c00
Use explicit instances when calling warnings.warn_explicit
2018-09-04 16:29:48 -03:00