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
Bruno Oliveira
a054aa4797
Issue assert rewrite warning if tuple >=1 as suggested in review
2018-09-04 14:45:48 -03:00
Bruno Oliveira
9ae0a3cd85
Do not trigger warning about tuples being always True if the tuple has size != 2
2018-09-04 13:41:11 -03:00
Bruno Oliveira
615c671434
Connect string literals
2018-09-04 13:34:05 -03:00
Bruno Oliveira
56d414177a
Remove nodeid from messages for warnings generated by standard warnings
...
Standard warnings already contain the proper location, so we don't need
to also print the node id
2018-09-04 11:35:34 -03:00
Bruno Oliveira
78ac7d99f5
Deprecate Config.warn and Node.warn, replaced by standard warnings
2018-09-04 11:35:34 -03:00
Bruno Oliveira
eec7081b8d
Make AssertionRewritingrHook use imp_find_module
2018-09-03 10:18:25 -03:00
Bruno Oliveira
4675912d89
Add tests for early rewrite bailout code and handle patterns with subdirectories
2018-09-01 10:59:21 -03:00
Fabio Zadrozny
d53e449296
Improve performance of assertion rewriting. Fixes #3918
2018-08-31 12:27:08 -03:00
Bruno Oliveira
82a7ca9615
Avoid possible infinite recursion when writing pyc files in assert rewrite
...
What happens is that atomic_write on Python 2.7 on Windows will try
to convert the paths to unicode, but this triggers the import of
the encoding module for the file system codec, which in turn triggers
the rewrite, which in turn again tries to import the module, and so on.
This short-circuits the cases where we try to import another file when
writing a pyc file; I don't expect this to affect anything because
the only modules that could be affected are those imported by
atomic_writes.
Fix #3506
2018-08-27 21:29:45 -03:00
Anthony Sottile
99e31f6fb1
Use `bytes` directly instead of `binary_type`
...
`bytes` is an alias for `str` in python2.6+
2018-08-23 18:55:21 -07:00
Anthony Sottile
c2cd337886
py.builtin.exec_ => six.exec_
2018-08-22 23:00:06 -07:00
Anthony Sottile
452e5c1cf0
Fix `TypeError` when the assertion message is `bytes` in python 3.
2018-08-01 15:09:25 -07:00
Anthony Sottile
cbaa7dd56a
Upgrade pre-commit hooks except pyupgrade
2018-06-26 06:35:27 -07:00
Anthony Sottile
1d55c49a9a
Fix `ImportWarning` triggered by explicit relative imports
2018-06-23 07:55:49 -07:00
Ronny Pfannschmidt
eaa882f3d5
switch to src layout
2018-05-26 09:10:38 +02:00