hp310780
27a4c6cd6d
Fix --help crash on add_ini(.., help='') and improve message on help=None ( #7427 )
2020-07-29 10:48:38 +03:00
Ran Benita
b36bcd13e9
mark: fix pylint not-callable error on pytest.mark.parametrize(...), again
...
Apparently the previous fix c1ca42b5c2
didn't work.
Hopefully this time I'm testing this correctly.
2020-07-29 10:39:13 +03:00
Ran Benita
3633b691d8
pathlib: make visit() independent of py.path.local, use os.scandir
...
`os.scandir()`, introduced in Python 3.5, is much faster than
`os.listdir()`. See https://www.python.org/dev/peps/pep-0471/ .
It also has a `DirEntry` which can be used to further reduce syscalls in
some cases.
2020-07-25 00:47:29 +03:00
Ran Benita
c15bb5d3de
pathlib: replace py.path.local.visit() with our own function
...
Part of reducing dependency on `py`. Also enables upcoming improvements.
In cases where there are simpler alternatives (in tests), I used those.
What's left are a couple of uses in `_pytest.main` and `_pytest.python`
and they only have modest requirements, so all of the featureful code
from py is not needed.
2020-07-25 00:26:49 +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
Bruno Oliveira
7ec6401ffa
Change pytest deprecation warnings into errors for 6.0 release ( #7362 )
...
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-07-22 21:36:51 -03:00
Anthony Sottile
8616a5f1d9
Preserve newlines when captured with capfd
2020-07-20 10:31:20 -07:00
Lewis Cowles
71ab6236a1
Clearer guidance on pytest.raise(match=...) failure ( #7499 )
2020-07-15 22:26:47 +03:00
Bruno Oliveira
e7c42ae62b
Inaccessible lock files now imply temporary directories can't be removed
...
Fix #7500
Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-07-15 09:25:17 -03:00
Ran Benita
41c40efe80
Merge pull request #7496 from bluetech/typing-idfn
...
Fix typing of params ids callable form
2020-07-15 10:25:46 +03:00
Ran Benita
fe1fcfd081
Merge pull request #7490 from bluetech/fix-dynamic-runtest-xfail
...
skipping: fix dynamic xfail mark added in runtest not respected
2020-07-15 10:25:29 +03:00
Ran Benita
bc17034a67
Fix typing of params ids callable form
...
The previous typing had an object passed to the user, which they can't
do anything with without asserting, which is inconvenient. Change it to
Any instead.
Note that what comes *back* to pytest (the return value) should be an
`object`, because we want to handle arbitrary objects without assuming
anything about them.
2020-07-14 14:53:42 +03:00
Ran Benita
1a73e78698
mark: fix typing for `@pytest.mark.xfail(raises=...)`
2020-07-14 01:39:04 +03:00
Ran Benita
ccad10a829
skipping: fix dynamic xfail mark added in runtest not respected
...
If a test runtest phase (not setup) dynamically adds a pytest.mark.xfail
mark to the item, it should be respected, but it wasn't. This regressed
in 3e6fe92b7e
(not released).
Fix it by just always refreshing the mark if needed. This is mostly what
was done before but in a more roundabout way.
2020-07-14 01:02:06 +03:00
Ran Benita
78f2dc08fa
skipping: slight simplification
2020-07-14 00:45:12 +03:00
Bruno Oliveira
07f5f6fd4a
Merge pull request #7481 from bluetech/tw-unicode-escape
...
terminalwriter: bring back handling of printing characters not supported by stdout
2020-07-11 16:01:45 -03:00
Simon K
7f467ebc9a
Create subdirectories if they do not exist when specified for log file ( #7468 )
...
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-07-11 13:40:28 -03:00
Ran Benita
7b65b2337b
Merge pull request #7472 from bluetech/cleanups-4
...
Some minor fixes & type annotations
2020-07-11 19:05:07 +03:00
Ran Benita
113339b029
terminalwriter: bring back handling of printing characters not supported by stdout
2020-07-11 18:59:00 +03:00
Bruno Oliveira
d466cc25a7
Merge pull request #7424 from nicoddemus/package-scope-experimental-7389
...
Remove package scope experimental status
2020-07-11 08:44:34 -03:00
Bruno Oliveira
0b58f73d44
Merge pull request #7476 from bluetech/pylint-callable
...
mark/structure: fix pylint complaining that builtin marks are not callable
2020-07-10 17:26:37 -03:00
Ran Benita
c1ca42b5c2
mark/structure: fix pylint complaining that builtin marks are not callable
2020-07-10 23:10:17 +03:00
Hugo van Kemenade
c1c5a2b34a
Add support for NO_COLOR and FORCE_COLOR ( #7466 )
...
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-07-10 08:49:10 -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
087b047426
cacheprovider: type annotations
2020-07-10 13:08:56 +03:00
Ran Benita
a2f021b6f3
Remove no longer needed `noqa: F821` uses
...
Not needed since pyflakes 2.2.0.
2020-07-10 13:08:56 +03:00
Ran Benita
fc702ab7e4
fixtures: some type annotations
2020-07-10 13:08:56 +03:00
Ran Benita
168d9adefc
hookspec: change Node -> Union[Item, Collector] to avoid exposing Node
...
We don't really want `Node` itself as a public API, only its two
subclasses.
2020-07-10 13:08:56 +03:00
Ran Benita
8e8d639276
tmpdir: type annotations
2020-07-10 13:08:56 +03:00
Ran Benita
bcff02c4c6
pytester: some type annotations
2020-07-10 13:08:56 +03:00
Ran Benita
c7a1db5d01
junitxml: few typing fixes & additions
2020-07-10 13:08:56 +03:00
Ran Benita
5da4a1d84f
capture: type annotate return value of fixtures
2020-07-10 13:08:56 +03:00
Ran Benita
e079ebbd57
python: more type annotations
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
Arvin Firouzi
c3e2b11a62
Fix reported location of skip when --runxfail is used ( #7432 )
...
Co-authored-by: Arvin Firouzi <427014@student.fontys.nl>
2020-07-09 23:10:32 +03:00
Vlad-Radz
678c1a0745
assertion: improve diff output of recursive dataclass/attrs
...
Co-authored-by: Vlad <uladzislau.radziuk@nordcloud.com>
2020-07-08 19:04:56 +03:00
Bruno Oliveira
93d2ccbfb7
Point to stable docs instead of latest
...
Now that our master might contain new features, it is best to point
users to the stable docs rather than the latest
2020-07-07 07:45:27 -03:00
Ran Benita
ef62b865f0
Merge pull request #7448 from bluetech/typing-publish
...
Publish our types
2020-07-05 16:51:26 +03:00
Ran Benita
2bcad38fbd
Publish our types
2020-07-04 13:18:15 +03:00
Ran Benita
36b958c99e
Merge pull request #7438 from bluetech/source-cleanups
...
code/source: some cleanups
2020-07-04 12:57:32 +03:00
Ran Benita
64dd7000e5
Merge pull request #7436 from bluetech/cleanup-lsof
...
pytester: slightly clean up LsofFdLeakChecker
2020-07-04 10:55:11 +03:00
Ran Benita
eced536eaf
Merge pull request #7435 from bluetech/python-cleanups
...
python: a few cleanups
2020-07-04 10:54:07 +03:00
Gleb Nikonorov
e596b26f1a
Don't quote the Match type since it's imported from Typing
2020-07-02 18:22:54 -04:00
Gleb Nikonorov
04d052e306
fix mypy issue by using typing Match instead of re.Match
2020-07-02 15:32:23 -04:00
Ran Benita
f5c69f3eb2
code/source: inline getsource()
...
The recursive way in which Source and getsource interact is a bit
confusing, just inline it.
2020-07-01 20:20:13 +03:00
Ran Benita
ef39115001
code/source: remove compiling functions
...
A lot of complex code that isn't used anymore outside of tests after
the previous commit.
2020-07-01 20:20:12 +03:00
Ran Benita
9640c9c9eb
skipping: use plain compile() instead of _pytest._code.compile()
...
eval() is used for evaluating string conditions in skipif/xfail e.g.
@pytest.mark.skipif("1 == 0")
This is the only code that uses `_pytest._code.compile()`, so removing
its last use enables us to remove it entirely.
In this case it doesn't add much. Plain compile() gives a good enough
error message.
For regular exceptions, the message is the same.
For SyntaxError exceptions, e.g. "1 ==", the previous code adds a little
bit of useful context:
```
invalid syntax (skipping.py:108>, line 1)
The above exception was the direct cause of the following exception:
1 ==
^
(code was compiled probably from here: <0-codegen /pytest/src/_pytest/skipping.py:108>) (line 1)
During handling of the above exception, another exception occurred:
Error evaluating 'skipif' condition
1 ==
^
SyntaxError: invalid syntax
```
The new code loses it:
```
unexpected EOF while parsing (<skipif condition>, line 1)
During handling of the above exception, another exception occurred:
Error evaluating 'skipif' condition
1 ==
^
SyntaxError: invalid syntax
```
Since the old message is a minor improvement to an unlikely error
condition in a deprecated feature, I think it is not worth all the code
that it requires.
2020-07-01 20:20:12 +03:00
Ran Benita
4a27d7d973
code/source: remove unused method Source.putaround()
2020-07-01 20:20:11 +03:00
Ran Benita
a7303b52db
code/source: remove unused method Source.isparseable()
2020-07-01 20:20:11 +03:00
Ran Benita
a127a22d13
code/source: remove support for comparing Source with str
...
Cross-type comparisons like this are a bad idea. This isn't used.
2020-07-01 20:20:10 +03:00
Ran Benita
2b99bfbc60
code/source: remove support for passing multiple parts to Source
...
It isn't used, so keep it simple.
2020-07-01 20:20:09 +03:00
Ran Benita
c83e16ab2e
code/source: remove unneeded assert
...
inspect.getsource() definitely returns str.
2020-07-01 20:20:09 +03:00
Ran Benita
c6083ab970
code/source: remove old IndentationError workaround in getsource()
...
This has been there since as far as the git history goes (2007), is not
covered by any test, and says "Buggy python version consider upgrading".
Hopefully everyone have upgraded...
2020-07-01 20:20:08 +03:00
Ran Benita
4108174777
code/source: remove Source(deindent: bool) parameter
...
Not used, except in tests.
2020-07-01 20:20:07 +03:00
Ran Benita
2fe178488a
code/source: expose deindent kwarg in signature
...
Probably was done to avoid the shadowing issue, but work around it
instead.
2020-07-01 20:20:06 +03:00
Ran Benita
7b1ba7c0db
pytester: slightly clean up LsofFdLeakChecker
2020-07-01 19:39:48 +03:00
Ruaridh Williamson
304f2916fc
logging: use unique handlers for caplog and reports
...
Setting log_level via the CLI or .ini will control the log level of the
report that is dumped upon failure of a test.
If caplog modified the log level during the execution of that test, it
should not impact the level that is displayed upon failure in the
"captured log report" section.
[
ran:
- rebased
- reused handler
- changed store keys also to "caplog_handler_*"
- added changelog
all bugs are mine :)
]
2020-07-01 19:30:03 +03:00
Ran Benita
ae83dbd4cf
python: remove ancient Function.repr_failure(outerr) parameter
...
This has been asserted like this since 04e9197fd6
(i.e. 11 years, pytest 1.0), seems safe to simply remove at this point.
2020-06-30 13:14:03 +03:00
Ran Benita
40c355f8c3
python: pytest_pycollect_makeitem doesn't need to be a hookwrapper
...
A trylast is more appropriate for this usecase.
hookwrappers are more complicated and more expensive than regular
hookimpls, so better avoided.
2020-06-30 13:14:03 +03:00
Ran Benita
e492b1d567
python: don't pass entire Item for generating ID
...
Just the nodeid is enough for the error messages.
This removes an import cycle.
2020-06-30 13:13:45 +03:00
Ran Benita
e6e300e729
Merge pull request #7396 from gnikonorov/issue_7295
...
Refactor src/_pytest/config/__init__.py to use the warnings module instead of stderr for warnings
2020-06-28 18:02:07 +03:00
Gleb Nikonorov
49ec2aed0f
change stacklevel in warnings from 2 to 3
2020-06-28 10:48:33 -04:00
Ran Benita
992a7a8d38
Merge pull request #7397 from lgeiger/reduce-ihook-calls
...
Reduce calls to item.ihook
2020-06-28 15:01:43 +03:00
Gleb Nikonorov
c39655725a
change if else structure of _warn_bout_missing_assertion
2020-06-27 19:49:19 -04:00
Gleb Nikonorov
72a39117a8
Merge remote-tracking branch 'origin' into issue_7295
2020-06-27 19:43:03 -04:00
Bruno Oliveira
289197ff22
Remove package scope experimental status
...
Close #7389
2020-06-27 11:16:50 -03:00
Ran Benita
7450b6dd95
Merge pull request #7418 from bluetech/typing-3
...
More typing work
2020-06-27 10:54:29 +03:00
gdhameeja
03230b4002
Fix-6906: Added code-highlight option to disable highlighting optionally
...
Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-06-26 13:24:56 -07:00
Lukas Geiger
97d2c711e6
Reduce calls of Node.ihook
2020-06-26 14:46:37 +02:00
Ran Benita
f382a6bb20
hookspec: remove unused hookspec pytest_doctest_prepare_content()
...
It's been unused for 10 years at lest from bb50ec89a9
.
2020-06-25 17:44:56 +03:00
Ran Benita
256a5d8b14
hookspec: improve typing of some remaining hooks
2020-06-25 17:33:21 +03:00
Ran Benita
97a11726e2
freeze_support: type annotate
2020-06-25 15:28:34 +03:00
Ran Benita
8f8f472379
python_api: type annotate some parts of pytest.approx()
2020-06-25 15:15:24 +03:00
Ran Benita
142d8963e6
recwarn: type annotate pytest.deprecated_call
...
Also improve its documentation.
2020-06-25 14:40:26 +03:00
Ran Benita
653c83e127
recwarn: type annotate recwarn fixture
2020-06-25 14:30:42 +03:00
Ran Benita
4d813fdf5e
recwarn: improve return type annotation of non-contextmanager pytest.warns
...
It returns the return value of the function.
2020-06-25 14:30:42 +03:00
Ran Benita
f00bec2a12
Replace yield_fixture -> fixture in internal code
...
`yield_fixture` is a deprecated alias to `fixture`.
2020-06-25 14:05:46 +03:00
Gleb Nikonorov
0dd77b3e39
Merge remote-tracking branch 'origin/master' into issue_7295
2020-06-23 23:21:36 -04:00
David Diaz Barquero
617bf8be5b
Add details to error message for junit ( #7390 )
...
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-06-23 13:03:46 -03:00
Ran Benita
3624acb665
Merge pull request #7401 from bluetech/typing-config
...
config: improve typing
2020-06-23 18:58:21 +03:00
Ran Benita
8994e1e3a1
config: make _get_plugin_specs_as_list a little clearer and more general
2020-06-23 11:47:52 +03:00
Ran Benita
04a6d37823
nodes: fix string possibly stored in Node.keywords instead of MarkDecorator
...
This mistake was introduced in 7259c453d6
.
2020-06-22 16:51:11 +03:00
Ran Benita
4655b79985
config: improve typing
2020-06-22 16:39:14 +03:00
Ran Benita
83891d9022
Merge pull request #7387 from cool-RR/2020-06-11-raise-from
...
Fix exception causes all over the codebase
2020-06-21 22:42:18 +03:00
Ran Benita
99d34ba029
Merge pull request #7388 from bluetech/mark-evaluate
...
skipping: refactor mark evaluation
2020-06-21 21:47:56 +03:00
Ran Benita
27492cf7a0
Merge pull request #7379 from bluetech/typing-builtin-marks
...
Type annotate pytest.mark.{skip,skipif,xfail,parametrize,usefixtures,filterwarnings}
2020-06-21 20:44:27 +03:00
Ran Benita
b3fb5a2d47
Type annotate pytest.mark.* builtin marks
2020-06-21 20:18:52 +03:00
Ran Benita
7d8d1b4440
skipping: better links in --markers output
...
Suggested by Bruno.
2020-06-21 20:15:10 +03:00
Ran Benita
c9737ae914
skipping: simplify xfail handling during call phase
...
There is no need to do the XPASS check here, pytest_runtest_makereport
already handled that (the current handling there is dead code).
All the hook needs to do is refresh the xfail evaluation if needed, and
check the NOTRUN condition again.
2020-06-21 19:54:29 +03:00
Gleb Nikonorov
ac89d6532a
replace stderr warnings with the warnings module
2020-06-20 12:15:58 -04:00
Ran Benita
3e6fe92b7e
skipping: refactor skipif/xfail mark evaluation
...
Previously, skipif/xfail marks were evaluated using a `MarkEvaluator`
class. I found this class very difficult to understand.
Instead of `MarkEvaluator`, rewrite using straight functions which are
hopefully easier to follow.
I tried to keep the semantics exactly as before, except improving a few
error messages.
2020-06-20 16:15:28 +03:00
Ram Rachum
dd446bee5e
Fix exception causes all over the codebase
2020-06-19 22:02:24 +03:00
Ran Benita
6072c9950d
skipping: move MarkEvaluator from _pytest.mark.evaluate to _pytest.skipping
...
This type was actually in `_pytest.skipping` previously, but was moved to
`_pytest.mark.evaluate` in cf40c0743c
.
I think the previous location was more appropriate, because the
`MarkEvaluator` is not a generic mark facility, it is explicitly and
exclusively used by the `skipif` and `xfail` marks to evaluate their
particular set of arguments. So it is better to put it in the plugin
code.
Putting `skipping` related functionality into the core `_pytest.mark`
module also causes some import cycles which we can avoid.
2020-06-19 13:33:54 +03:00
Ran Benita
a1f841d5d2
skipping: use pytest_runtest_call instead of pytest_pyfunc_call
...
`@pytest.mark.xfail` is meant to work with arbitrary items, and there is
a test `test_mark_xfail_item` which verifies this.
However, the code for some reason uses `pytest_pyfunc_call` for the
call phase check, which only works for Function items. The test
mentioned above only passed "accidentally" because the
`pytest_runtest_makereport` hook also runs a `evalxfail.istrue()` which
triggers and evaluation, but conceptually it shouldn't do that.
Change to `pytest_runtest_call` to make the xfail checking properly
generic.
2020-06-19 13:33:53 +03:00
Gleb Nikonorov
4cc4ebf3c9
Don't treat ini keys defined in conftest.py as invalid ( #7384 )
2020-06-18 12:58:41 -03:00
Andrew
a67c553beb
Disable caching when evaluating expressions in marks ( #7373 )
2020-06-16 12:39:36 +03:00
Ran Benita
b6fd89ef31
Merge pull request #7370 from bluetech/typing3
...
Some type annotations, doc improvements
2020-06-16 11:23:57 +03:00