Commit Graph

2455 Commits

Author SHA1 Message Date
Ran Benita 172b6e15c5 hookspec: improve collection phase documentation a bit
Make it a bit more accurate and use the same format that
pytest_runtest_protocol uses.
2020-08-24 13:00:09 +03:00
Ran Benita bb38ae9c52
Merge pull request #7651 from bluetech/capture-safe-disable
capture: fix disabled()/global_and_fixture_disabled() enabling capturing when it was disabled
2020-08-24 12:11:09 +03:00
Ran Benita 143e3ab846
Merge pull request #7673 from bluetech/logging-fix-handler-restore
logging: fix handler level restored incorrectly if caplog.set_level is called more than once
2020-08-23 12:06:09 +03:00
Ran Benita 837687c21a
Merge pull request #7668 from bluetech/dir-match-msg
main: improve message on `pytest path/to/a/directory::mytest`
2020-08-23 12:05:22 +03:00
Ran Benita b1354608cc logging: fix handler level restored incorrectly if caplog.set_level is called more than once 2020-08-22 17:46:23 +03:00
Maximilian Cosmo Sitter 75af2bfa06
Reintroduce warnings postponed in 6.0 (#7637) 2020-08-22 11:17:50 -03:00
Ran Benita 5e39cd5e71 main: improve message on `pytest path/to/a/directory::mytest`
The path part of a `<path>::part1::part2` style collection argument must
be a file, not a directory.

Previously this crashed with an uncool assert "invalid arg".
2020-08-22 11:52:54 +03:00
Bruno Oliveira 372a094005 PytestDeprecationWarning no longer a hard error 2020-08-19 08:14:28 -03:00
Bruno Oliveira ef946d557c Remove resultlog plugin 2020-08-19 08:14:28 -03:00
Bruno Oliveira 52b0cc4f19 Remove broken pytest_collect_directory hook 2020-08-19 08:14:25 -03:00
Bruno Oliveira 457d351941 Remove deprecated TerminalReporter.writer property 2020-08-19 08:13:34 -03:00
Bruno Oliveira 6ecbd008c4 Change junit_family default to xunit2 2020-08-19 08:13:06 -03:00
Bruno Oliveira 73e06373dc Hard failure when constructing Node subclasses 2020-08-19 08:13:03 -03:00
Bruno Oliveira c747dc5248 Drop support for positional arguments in @pytest.fixture 2020-08-19 08:11:42 -03:00
Bruno Oliveira 98530184a5 Remove funcargnames compatibility property 2020-08-19 08:11:39 -03:00
Ran Benita c98525bd21
Merge pull request #7648 from bluetech/pylint-abc2
Only define gethookproxy, isinitpath on Session
2020-08-18 15:45:11 +03:00
Bruno Oliveira afa4760cb8
Merge pull request #7643 from nicoddemus/issue-7628 2020-08-17 16:58:56 -03:00
Ran Benita 0d5a65091d capture: fix disabled()/global_and_fixture_disabled() enabling capturing when it was disabled
The `CaptureManager.global_and_fixture_disabled()` context manager (and
`CaptureFixture.disabled()` which calls it) did `suspend(); ...;
resume()` but if the capturing was already suspended, the `resume()`
would resume it when it shouldn't.

This caused caused some messages to be swallowed when `--log-cli` is
used because it uses `global_and_fixture_disabled` when capturing is not
necessarily resumed.
2020-08-16 23:21:45 +03:00
Bruno Oliveira b426bb3443 Refactor Session._parsearg into a separate function for testing 2020-08-15 13:23:55 -03:00
Bruno Oliveira 2213016e40 Fix Module.name from full path without drive letter
Fix #7628
2020-08-15 09:39:14 -03:00
Bruno Oliveira 3f0abcc6a5
Merge pull request #7639 from nicoddemus/issue-7638 2020-08-15 09:17:37 -03:00
Ran Benita eddd993cf4 Only define gethookproxy, isinitpath on Session
This fixes an issue where pylint complains about missing implementations
of abstract methods in subclasses of `File` which only override
`collect()` (as they should).

It is also cleaner and makes sense, these methods really don't need to
be overridden.

The previous methods defined directly on `FSCollector` and `Package` are
deprecated, to be removed in pytest 7.

See commits e2934c3f8c and
f10ab021e2 for reference.
2020-08-15 13:40:16 +03:00
Bruno Oliveira f76b162263 Add ref to Python bug 2020-08-14 11:36:07 -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
Bruno Oliveira 36c8bb492e get_dirs_from_args handles paths with invalid syntax
Fix #7638
2020-08-12 17:20:09 -03:00
Ran Benita acc9310c17 capture: add type annotations to CaptureFixture
It now has a str/bytes type parameter.
2020-08-10 18:14:47 +03:00
Ran Benita 8a66f0a96d capture: overcome a mypy limitation by making CaptureResult a regular class
See the code comment for the rationale.
2020-08-10 18:14:47 +03:00
Ran Benita f8c4e038fd Replace some usages of py.path.local 2020-08-06 18:46:17 +03:00
Ran Benita 70f3ad1c1f config/findpaths: convert from py.path.local to pathlib 2020-08-06 18:46:17 +03:00
Ran Benita 9e55288ba4 pathlib: add absolutepath() as alternative to Path.resolve()
Didn't call it absolute or absolute_path to avoid conflicts with
possible variable names.

Didn't call it abspath to avoid confusion with os.path.abspath.
2020-08-06 18:16:04 +03:00
Ran Benita e0d0951945 pathlib: add analogues to py.path.local's bestrelpath and common
An equivalent for these py.path.local functions is needed for some
upcoming py.path -> pathlib conversions.
2020-08-06 18:16:04 +03:00
Ran Benita fbf251f11d Improve typing of reports' longrepr field 2020-08-04 22:52:24 +03:00
Ran Benita f0eb82f7d4 pytester: improve type annotations 2020-08-04 22:46:30 +03:00
Ran Benita 62ddf7a0e5 resultlog: add missing type annotations 2020-08-04 22:45:46 +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
Bruno Oliveira 6882c0368b
Merge pull request #7593 from bluetech/typing-no-implicit-reexport
typing: set no_implicit_reexport
2020-08-01 11:03:47 -03:00
Ran Benita 8d98de8f8a typing: set no_implicit_reexport
In Python, if module A defines a name `name`, and module B does `import
name from A`, then another module C can `import name from B`.

Sometimes it is intentional -- module B is meant to "reexport" `name`.
But sometimes it is just confusion/inconsistency on where `name` should
be imported from.

mypy has a flag `--no-implicit-reexport` which puts some order into
this. A name can only be imported from a module if

1. The module defines the name
2. The module's `__all__` includes the name
3. The module imports the name as `from ... import .. as name`.

This flag is included in mypy's `--strict` flag.

I like this flag, but I realize it is a bit controversial, and in
particular item 3 above is a bit unfriendly to contributors who don't
know about it. So I didn't intend to add it to pytest.

But while investigating issue 7589 I came upon mypy issue 8754 which
causes `--no-implicit-reexport` to leak into installed libraries and
causes some unexpected typing differences *in pytest* if the user uses
this flag.

Since the diff mostly makes sense, let's just conform to it.
2020-07-31 10:09:11 +03:00
Ran Benita 96a48f0c66 Stop using more-itertools
We barely use it; the couple places that do are not really worth the
extra dependency, I think the code is clearer without it.

Also simplifies one (regular) itertools usage.

Also improves a check and an error message in `pytest.raises`.
2020-07-30 20:19:24 +03:00
Bruno Oliveira 095bf191e2
Merge pull request #7561 from nicoddemus/longreprtext-7559 2020-07-29 09:47:04 -03:00
Bruno Oliveira d3267bc49d Fix TestReport.longreprtext when TestReport.longrepr is not a string
Fix #7559
2020-07-29 09:31:15 -03:00
Ran Benita 0e0275d8d9 logging: fix capture handler level not reset on teardown after caplog.set_level()
This probably regressed in fcbaab8.
2020-07-29 14:59:29 +03:00
Ran Benita 422685d0bd
Merge pull request #7567 from bluetech/pylint-callable-2-space
mark: fix extraneous spaces in dummy type-checking marks
2020-07-29 12:40:21 +03:00
Ran Benita b473e515bc
Merge pull request #7541 from bluetech/py-visit
pathlib: stop using py.path.local.visit(), use os.scandir
2020-07-29 12:04:06 +03:00
Ran Benita 20a3a28815
Merge pull request #7536 from bluetech/junitxml-etree
junitxml: convert from py.xml to xml.etree.ElementTree
2020-07-29 12:01:33 +03:00
Ran Benita 54e08b7230 mark: fix extraneous spaces in dummy type-checking marks 2020-07-29 11:58:54 +03:00
Ran Benita f9837f953c
Merge pull request #7565 from bluetech/pylint-callable-2
mark: fix pylint not-callable error on pytest.mark.parametrize(...), again
2020-07-29 11:49:41 +03:00
Ran Benita f86e4516eb junitxml: convert from py.xml to xml.etree.ElementTree
Part of the effort to reduce dependency on the py library.

Besides that, py.xml implements its own XML serialization which is
pretty scary.

I tried to keep the code with minimal changes (though it could use some
cleanups). The differences in behavior I have noticed are:

- Attributes in the output are not sorted.

- Some unneeded escaping is no longer performed, for example escaping
  `"` to `&quot;` in a text node.
2020-07-29 10:52:21 +03:00
Ran Benita 1653c49b1b junitxml: simplify bin_xml_escape
1. Remove sys.maxunicode check & comment. Nowadays it is always a
   constant 0x10ffff.
2. Pre-generate the pattern. Possible due to 1.
3. Compile the regex lazily. No reason to pay startup cost for it.
4. Add docstring in particular to explain a subtle point.
2020-07-29 10:52:21 +03:00
Ran Benita 6ea6f0dac8 junitxml: compile a regex lazily
Instead of slowing down startup, and making the code harder to follow,
compile it lazily (it is still cached internally).
2020-07-29 10:52:21 +03:00
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
Bruno Oliveira db00612b84
Merge pull request #7364 from nicoddemus/parseoutcomes-plural-6505
assertoutcomes() only accepts plural forms
2020-06-15 20:27:40 -03:00
Ronny Pfannschmidt 4e5a7b7d2f
Merge pull request #7366 from gnikonorov/issue_7346
Allow users to provide version information to the required_plugins INI key
2020-06-15 20:19:05 +02:00
Ran Benita 7b77fc086a
Merge pull request #7368 from bluetech/teardown-in-setup
runner: don't try to teardown previous items from pytest_runtest_setup
2020-06-15 19:41:21 +03:00
Ran Benita 4f4c2638d0
Merge pull request #7351 from cool-RR/2020-06-11-raise-from
Fix exception causes in config/__init__.py
2020-06-14 18:03:56 +03:00
Ran Benita da1124eb98 hookspec: improve runtest hooks documentation 2020-06-14 17:31:38 +03:00
Ran Benita 2a38ca8a0c doc/reference: add CollectReport
CollectReport appears in several hooks, so we should document it. It's
runtest equivalent TestReport is already documented.
2020-06-14 16:55:41 +03:00
Ran Benita bb878a2b13 runner: don't try to teardown previous items from pytest_runtest_setup
While working on improving the documentation of the
`pytest_runtest_setup` hook, I came up with this text:

> Called to perform the setup phase of the test item.
>
> The default implementation runs ``setup()`` on item and all of its
> parents (which haven't been setup yet). This includes obtaining the
> values of fixtures required by the item (which haven't been obtained
> yet).

But upon closer inspection I noticed this line at the start of
`SetupState.prepare` (which is what does the actual work for
`pytest_runtest_setup`):

    self._teardown_towards(needed_collectors)

which implies that the setup phase of one item might trigger teardowns
of *previous* items. This complicates the simple explanation. It also
seems like a completely undesirable thing to do, because it breaks
isolation between tests -- e.g. a failed teardown of one item shouldn't
cause the failure of some other items just because it happens to run
after it.

So the first thing I tried was to remove that line and see if anything
breaks -- nothing did. At least pytest's own test suite runs fine. So
maybe it's just dead code?
2020-06-14 13:48:05 +03:00
Ran Benita 314d00968a hookspec: type annotate pytest_runtest_log{start,finish} 2020-06-14 12:51:06 +03:00
Ran Benita bb7b3af9b9 hookspec: fix return type annotation of pytest_runtest_makereport 2020-06-13 22:30:00 +03:00
Ran Benita 25064eba7a pytest.collect: type annotate (backward compat module)
This is just to satisfy typing coverage.
2020-06-13 22:29:24 +03:00
Gleb Nikonorov 320625527a Add more tests and docs 2020-06-13 11:22:18 -04: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
Bruno Oliveira 2c37585f58
Merge pull request #7258 from piotrhm/issue_6471 2020-06-13 11:14:18 -03:00
Gleb Nikonorov 8a022c0ce3 test to make sure precommit is fixed 2020-06-13 09:57:13 -04:00
Gleb Nikonorov 7ea116d74c Merge remote-tracking branch 'origin' into issue_7346 2020-06-13 09:54:23 -04:00
Bruno Oliveira 3151219785 assertoutcomes() only accepts plural forms
Fix #6505
2020-06-13 10:29:22 -03:00
Ran Benita f551cab877
Merge pull request #7358 from bluetech/typing2
More type annotations, fix some typing bugs
2020-06-13 10:44:11 +03:00
Gleb Nikonorov 6f8633cc17 add in solution barring documentation 2020-06-13 02:47:15 -04:00
Bruno Oliveira aaa6f1c3fa
Merge pull request #7330 from gnikonorov/issue_7305 2020-06-12 19:35:38 -03:00
Ram Rachum caa984c029 Fix exception causes in config/__init__.py 2020-06-12 18:49:57 +03:00
Ran Benita a5ab7c19fb config: reject minversion if it's a list instead of a single string
Fixes:

src/_pytest/config/__init__.py:1071: error: Argument 1 to "Version" has incompatible type "Union[str, List[str]]"; expected "str"  [arg-type]
2020-06-12 17:34:31 +03:00
Ran Benita 1cf9405075 Fix some type errors around py.path.local
These errors are found using a typed version of py.path.local.
2020-06-12 17:34:31 +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 7081ed19b8 hookspec: type annotate pytest_keyboard_interrupt 2020-06-12 17:34:31 +03:00
Ran Benita b4f046b777 monkeypatch: add type annotations 2020-06-12 17:34:31 +03:00
Ran Benita f84ffd9747 Remove unused type: ignores
Not needed since update from mypy 0.770 -> 0.780.
2020-06-12 17:34:31 +03:00
Zac Hatfield-Dodds 0f30103d9c
Merge pull request #7356 from Zac-HD/emancipate
Finish deprecation of "slave"
2020-06-12 23:13:11 +10:00
Zac-HD 564b2f707d Finish deprecation of "slave" 2020-06-12 22:49:33 +10:00
Gleb Nikonorov 2c8e356174 rename _emit_warning_or_fail to _warn_or_fail_if_strict and fix a doc typo 2020-06-12 08:27:55 -04:00
Bruno Oliveira ab331c906e Suppress errors while removing tmpdir's lock files
Fix #5456
2020-06-11 18:59:51 -03:00
Gleb Nikonorov c18afb59f5 final touches 2020-06-10 19:09:24 -04:00
Gleb Nikonorov 95cb7fb676 review feedback 2020-06-10 00:44:22 -04:00
ibriquem e2e7f15b71 Make dataclasses/attrs comparison recursive, fixes #4675 2020-06-09 14:39:40 -03:00
piotrhm f0e47c1ed6 Fix typo 2020-06-09 11:17:31 -03:00
piotrhm bde0ebcda9 Replace cleanup_numbered_dir with atexit.register 2020-06-09 11:17:31 -03:00
Bruno Oliveira 357f9b6e83 Add type annotations 2020-06-08 22:26:14 -03:00
piotrhm 51fb11c1d1 Added tests 2020-06-08 22:26:14 -03:00
piotrhm 0b70300ba4 Added requested modifications 2020-06-08 22:26:14 -03:00
Bruno Oliveira fcbaab8b0b
Allow tests to override "global" `log_level` (rebased) (#7340)
Co-authored-by: Ruaridh Williamson <ruaridh.williamson@flexciton.com>
2020-06-08 22:05:46 -03:00
Prashant Anand e78207c936
7119: data loss with mistyped --basetemp (#7170)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-06-08 21:54:22 -03:00
Fabio Zadrozny 322190fd84
Fix issue where working dir becomes wrong on subst drive on Windows. Fixes #5965 (#6523)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-06-08 10:56:40 -03:00
Bruno Oliveira c17d50829f
Add pyproject.toml support (#7247) 2020-06-08 10:03:10 -03:00
Gleb Nikonorov d2bb67bfda validate plugins before keys in config files 2020-06-07 14:10:20 -04:00
Gleb Nikonorov f1746c50ea Merge remote-tracking branch 'origin/master' into issue_7305 2020-06-06 12:37:56 -04:00
Gleb Nikonorov 3f6b3e7faa update help for --strict-config 2020-06-06 11:33:28 -04:00
Gleb Nikonorov f760b105ef Touchup pre-PR 2020-06-06 11:06:08 -04:00
Gleb Nikonorov 2a3c21645e Commit solution thus far, needs to be polished up pre PR 2020-06-06 02:38:18 -04:00
Ran Benita 1deaa74345 mark/expression: prevent creation of illegal Python identifiers
This is rejected by Python DEBUG builds, as well as regular builds in
future versions.
2020-06-05 15:57:48 +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
Ran Benita 71dfdca4df Enable check_untyped_defs mypy option for src/
This option checks even functions which are not annotated. It's a good
step to ensure that existing type annotation are correct.

In a Pareto fashion, the last few holdouts are always the ugliest,
beware.
2020-06-05 11:34:20 +03:00
Ran Benita 848ab00663 Type annotate `@pytest.mark.foo` 2020-06-05 11:34:20 +03:00
Ran Benita c0af19d8ad Type annotate more of _pytest.terminal 2020-06-05 11:34:20 +03:00
Ran Benita 2833884688 Type annotate pytest.fixture and more improvements to _pytest.fixtures 2020-06-05 11:34:20 +03:00
Ran Benita 8bcf1d6de1 Remove duplicated conversion of pytest.fixture() params argument
The FixtureFunctionMarker attrs class already converts the params
itself.

When adding types, the previous converter composition causes some type
error, but extracting it to a standalone function fixes the issue (a
lambda is not supported by the mypy plugin, currently).
2020-06-05 11:34:20 +03:00
Ran Benita 1bd7d025d9 Type annotate more of _pytest.fixtures 2020-06-05 11:34:20 +03:00
Ran Benita f8bb61ae5b Type annotate _pytest.warnings 2020-06-05 11:34:20 +03:00
Ran Benita 01797e6370 Type annotate _pytest.debugging (a bit) 2020-06-05 11:34:20 +03:00
Ran Benita 216a010ab7 Type annotate _pytest.junitxml 2020-06-05 11:34:20 +03:00
Ran Benita 3e351afeb3 Type annotate _pytest.capture 2020-06-05 11:34:20 +03:00
Ran Benita b51ea4f1a5 Type annotate _pytest.unittest 2020-06-05 11:34:20 +03:00
Ran Benita db52928684 Type annotate _pytest.logging 2020-06-05 11:34:20 +03:00
Ran Benita 90e58f8961 Type annotate some parts related to runner & reports 2020-06-05 11:34:20 +03:00
Ran Benita 709bcbf3c4 Type annotate _pytest.mark.evaluate 2020-06-05 11:34:20 +03:00
Ran Benita fc325bc0c3 Type annotate more of _pytest.nodes 2020-06-05 11:34:19 +03:00
Ran Benita 32dd0e87cb Type annotate _pytest.doctest 2020-06-05 11:34:19 +03:00
Ran Benita 387d9d04f7 Type annotate tricky reorder_items() function in fixtures.py 2020-06-05 11:34:19 +03:00
Ran Benita e68a26199c Type annotate misc functions 2020-06-05 11:34:19 +03:00
Ran Benita d95132178c Type annotate _pytest.assertion 2020-06-05 11:34:19 +03:00
Ran Benita 30e3d473c4 Type annotate _pytest._io.saferepr 2020-06-05 11:34:19 +03:00
Ran Benita 247c4c0482 Type annotate some more hooks & impls 2020-06-05 11:34:19 +03:00
Ran Benita ef34729541 Type annotate fixtures.py & related 2020-06-05 11:34:19 +03:00
Ran Benita be00e12d47 Type annotate main.py and some parts related to collection 2020-06-05 11:34:19 +03:00
Ran Benita f8de424241 Type annotate CallSpec2 2020-06-05 11:34:19 +03:00
Ran Benita 0fb081aec6 Type annotate some hookspecs & impls
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-06-05 11:34:19 +03:00
Ran Benita ff8b7884e8 Type annotate ParameterSet 2020-06-05 11:34:19 +03:00
Ran Benita 43fa1ee8f9 Type annotate some misc places with no particular connection 2020-06-05 11:34:19 +03:00
Ran Benita e7c26a92d7
Merge pull request #7253 from bluetech/fixture-special-case
fixtures: remove special cases when deciding when pytest.fixture() is a direct decoration
2020-06-05 11:33:43 +03:00
Bruno Oliveira cf640a9b67
Merge pull request #7292 from kerizane/7259_iniconfig 2020-06-03 19:00:48 -03:00
Bruno Oliveira 61a6ac9705
Merge pull request #7242 from nicoddemus/fix-flaky-test
Introduce _pytest.timing as a way to control timing during internal tests
2020-06-02 20:25:02 -03:00
Bruno Oliveira 8ac18bbecb Show invalid ini keys sorted
Otherwise this relies on the dictionary order of `config.inicfg`, which
is insertion order in py36+ but "random" order in py35.
2020-06-02 16:01:47 -03:00
Ran Benita 85b5a289f0
warnings: fix missing None in existing hook & add some docs (#7288) 2020-06-02 19:59:25 +03:00
Bruno Oliveira 7a8b8a5c9f
Merge branch 'master' into fix-flaky-test 2020-06-02 11:33:15 -03:00
Ronny Pfannschmidt 8faf1e8eca
Merge pull request #7286 from gnikonorov/issue_6856
Output a warning to stderr when an invalid key is read from an INI config file
2020-06-02 15:47:02 +02:00
Tor Colvin fe64093411
Fix removal of very long paths on Windows (#6755)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-06-02 08:56:33 -03:00
Keri Volans 2748feed38 7291: Replace py.iniconfig with iniconfig 2020-06-01 18:09:57 +01:00
Bruno Oliveira 70b5bdf4ba
Merge pull request #7264 from bluetech/wcwidth
Improve our own wcwidth implementation and remove dependency on wcwidth package
2020-05-31 12:37:58 -03:00
Gleb Nikonorov 92d15c6af1 review feedback 2020-05-31 11:33:31 -04:00
Ronny Pfannschmidt c16ede5ce6
Merge pull request #7255 from gnikonorov/issue_4049
Add new hook pytest_warning_recorded
2020-05-31 12:47:46 +02:00
Gleb Nikonorov db203afba3 Add in --strict-config flag to force warnings to errors 2020-05-31 02:45:40 -04:00
Gleb Nikonorov eef4f87e7b Output a warning to stderr when an invalid key is read from an INI config file 2020-05-30 20:36:02 -04:00
Bruno Oliveira 757bded135 Use Path() instead of str for path comparison
On Windows specifically is common to have drives diverging just by
casing ("C:" vs "c:"), depending on the cwd provided by the user.
2020-05-30 20:05:21 -03:00
Daniel Hahler fb9f277a99 Node._repr_failure_py: use abspath with changed cwd
Fixes https://github.com/pytest-dev/pytest/issues/6428.
2020-05-30 20:02:47 -03:00
Bruno Oliveira 56bf819c2f
Do not call TestCase.tearDown for skipped tests (#7236)
Fix #7215
2020-05-30 14:33:22 -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
Gleb Nikonorov 14de08011b fix the unit tests, add the proper deprecation warning, and add in a changelog entry 2020-05-27 23:03:07 -04:00
Anthony Sottile b3db440d4c
Merge pull request #7257 from DahlitzFlorian/fix-issue-6956
Prevent pytest from printing ConftestImportFailure traceback
2020-05-27 13:49:43 -07:00
Ran Benita 7a704288df capture: remove unneeded getattr
This attribute is set in __init__ and not deleted. Other methods do it
already but this one wasn't updated.
2020-05-27 15:27:16 +03:00
Ran Benita a35800c2e1 capture: formalize and check allowed state transition in capture classes
There are state transitions start/done/suspend/resume and two additional
operations snap/writeorg.

Previously it was not well defined in what order they can be called, and
which operations are idempotent.

Formalize this and enforce using assert checks with informative error
messages if they fail (rather than random AttributeErrors).
2020-05-27 15:27:15 +03:00
Ran Benita fd3ba053cf capture: don't assume that the tmpfile is backed by a BytesIO
Since tmpfile is a parameter to SysCapture, it shouldn't assume things
unnecessarily, when there is an alternative.
2020-05-27 15:19:30 +03:00
Ran Benita 97bcf5a3a2 capture: reorder file into sections and avoid forward references
Make it easier to read the file in progression, and avoid forward
references for upcoming type annotations.

There is one cycle, CaptureManager <-> CaptureFixture, which is hard to
untangle.

(This commit should be added to `.gitblameignore`).
2020-05-27 15:19:28 +03:00
Gleb Nikonorov d742b386c3 provide missing location parameter, and add type annotations to the hookspec 2020-05-27 00:53:31 -04:00
Ran Benita aca534c67d Improve our own wcwidth implementation and remove dependency on wcwidth package
`TerminalWriter`, imported recently from `py`, contains its own
incomplete wcwidth (`char_with`/`get_line_width`) implementation. The
`TerminalReporter` also needs this, but uses the external `wcwidth`
package.

This commit brings the `TerminalWriter` implementation up-to-par with
`wcwidth`, moves to implementation to a new file `_pytest._io.wcwidth`
which is used everywhere, and removes the dependency.

The differences compared to the `wcwidth` package are:

- Normalizes the string before counting.

- Uses Python's `unicodedata` instead of vendored Unicode tables. This
  means the data corresponds to the Python's version Unicode version
  instead of the `wcwidth`'s package version.

- Apply some optimizations.
2020-05-26 17:14:01 +03:00
Ran Benita 5507752c53 fixtures: remove special cases when deciding when pytest.fixture() is a direct decoration
pytest.fixture() can be used either as

    @pytest.fixture
    def func(): ...

or as

    @pytest.fixture()
    def func(): ...

or (while maybe not intended)

    func = pytest.fixture(func)

so it needs to inspect internally whether it got a function in the first
positional argument or not.

Previously, there were was oddity. In the following,

    func = pytest.fixture(func, autouse=True)
    # OR
    func = pytest.fixture(func, parms=['a', 'b'])

The result is as if `func` wasn't passed.

There isn't any reason for this special that I can understand, so remove
it.
2020-05-26 11:48:40 +03:00
Florian Dahlitz 95bd232e57
Apply suggestions from @bluetech 2020-05-26 10:31:53 +02:00
Ran Benita ea3f44894f capture: replace TeeSysCapture with SysCapture(tee=True)
This is more straightforward and does not require duplicating the
initialization logic.
2020-05-26 00:25:49 +03:00
Ran Benita 02c95ea624 capture: remove unused FDCapture tmpfile argument 2020-05-26 00:25:49 +03:00
Ran Benita 2695b41df3 capture: inline _capturing_for_request to simplify the control flow
With straight code, it is a little easier to understand, and simplify
further.
2020-05-26 00:25:49 +03:00
Ran Benita 491239d9b2 capture: remove some indirection in MultiCapture
Removing this indirection enables some further clean ups.
2020-05-26 00:25:49 +03:00
Florian Dahlitz 5ebcb34fb5
Move ConftestImportFailure check to correct position and add typing 2020-05-25 20:19:28 +02:00
Gleb Nikonorov 125b663f20 Address all feedback, minus the empty sring v None nodeid which is being discussed 2020-05-25 11:18:24 -04:00
Florian Dahlitz 6546d1f725
Prevent pytest from printing ConftestImportFailure traceback 2020-05-25 13:57:03 +02:00
Gleb Nikonorov 088d400b2d rename pytest_warning_record -> pytest_warning_recorded 2020-05-24 20:43:23 -04:00
Gleb Nikonorov b02d087dbd cleanup code pre pr 2020-05-24 20:26:14 -04:00
Gleb Nikonorov 9ee6550181 Add in a new hook pytest_warning_recorded for warning capture
communication
2020-05-24 19:05:24 -04:00
Anthony Sottile 45f53266e6
Merge pull request #7244 from DahlitzFlorian/fix-issue-7150
Prevent hiding underlying exception when ConfTestImportFailure is raised
2020-05-23 12:09:42 -07:00
Bruno Oliveira 1780924b27 Introduce _pytest.timing as a way to control timing during tests
_pytest.timing is an indirection to 'time' functions, which pytest production
code should use instead of 'time' directly.

'mock_timing' is a new fixture which then mocks those functions, allowing us
to write time-reliable tests which run instantly and are not flaky.

This was triggered by recent flaky junitxml tests on Windows related to timing
issues.
2020-05-23 11:50:33 -03:00
Claire Cecil 79701c65ed
Added support for less verbose version information (#7169) 2020-05-23 11:27:58 -03:00
Simon K 05c22ff823
7154-Improve-testdir-documentation-on-makefiles (#7239) 2020-05-23 11:27:06 -03:00
Ran Benita b38edec60f
Merge pull request #7238 from bluetech/micro-optimizations-1
A few tiny micro-optimizations/simplifications
2020-05-23 12:14:24 +03:00
Florian Dahlitz d0eb86cfa6
Prevent hiding underlying exception when ConfTestImportFailure is raised 2020-05-22 22:58:35 +02:00
Ran Benita 4a1557fa0e
Merge pull request #7091 from bluetech/capture-invalid-fd
Perform FD capturing even if the FD is invalid
2020-05-22 14:36:49 +03:00
Ran Benita f1f9c7792b Import `packaging` package lazily 2020-05-22 14:33:29 +03:00
Ran Benita 796fba6788 terminal: remove redundant write_fspath_result call
This is already done in pytest_runtest_logstart, so the fspath is
already guaranteed to have been printed (for xdist, it is disabled
anyway).

write_fspath_result is mildly expensive so it is worth avoiding calling
it twice.
2020-05-22 14:33:29 +03:00
Ran Benita 139a029b5e terminal: remove a redundant line
`write_fspath_result` already does this split.
2020-05-22 14:33:29 +03:00
Ran Benita 8d841ab0b8 nodes: remove unused argument from FSHookProxy 2020-05-22 14:33:28 +03:00
Ran Benita 919ac2239d
Merge pull request #7231 from bluetech/logging-error
logging: propagate errors during log message emits
2020-05-22 14:27:26 +03:00
Ran Benita eaeafd7c30 Perform FD capturing even if the FD is invalid
The `FDCapture`/`FDCaptureBinary` classes, used by `capfd`/`capfdbinary`
fixtures and the `--capture=fd` option (set by default), redirect FDs
1/2 (stdout/stderr) to a temporary file. To do this, they need to save
the old file by duplicating the FD before redirecting it, to be restored
once finished.

Previously, if this duplicating (`os.dup()`) failed, most likely due to
that FD being invalid, the FD redirection would silently not be done. The
FD capturing also performs python-level redirection (monkeypatching
`sys.stdout`/`sys.stderr`) which would still be done, but direct writes
to the FDs would fail.

This is not great. If pytest is run with `--capture=fd`, or a test is
using `capfd`, it expects writes to the FD to work and be captured,
regardless of external circumstances.

So, instead of disabling FD capturing, keep the redirection to a
temporary file, just don't restore it after closing, because there is
nothing to restore to.
2020-05-20 19:32:37 +03:00
Bruno Oliveira 0a03217903
Merge pull request #7046 from blueyed/k-skip-session-upstream 2020-05-19 20:09:36 -03:00
Daniel Hahler 691a7fceea Revisit some help texts with regard to newlines 2020-05-19 19:34:08 -03:00
Daniel Hahler 87423d3cc8 Keep explicit newlines with help texts
This makes a difference for e.g. pytest-xdist:

Before:
```
  --dist=distmode       set mode for distributing tests to exec environments. each: …
                        available environment. loadscope: …
                        grouped by file to any available environment. (default) no: …
```

After:
```
  --dist=distmode       set mode for distributing tests to exec environments.
                        each: send each test to all available environments.
                        load: load balance by sending any pending test to any available environment.
                        …
                        (default) no: run tests inprocess, don't distribute.
```

This might also result in unexpected changes (hard wrapping), when line
endings where used unintentionally, e.g. with:

```
help="""
    some long
    help text
    """
```

But the benefits from that are worth it, and it is easy to fix, as will
be done for the internal `assertmode` option.
2020-05-19 19:34:08 -03:00
Bruno Oliveira 5a6296a2d7
Merge pull request #7226 from nicoddemus/remove-function-args 2020-05-19 18:53:23 -03:00
Ran Benita b13fcb23d7 logging: propagate errors during log message emits
Currently, a bad logging call, e.g.

    logger.info('oops', 'first', 2)

triggers the default logging handling, which is printing an error to
stderr but otherwise continuing.

For regular programs this behavior makes sense, a bad log message
shouldn't take down the program. But during tests, it is better not to
skip over such mistakes, but propagate them to the user.
2020-05-19 11:16:39 +03:00
Ran Benita 85a06cfafb
Merge pull request #7227 from bluetech/logging-reuse-handler
logging: reuse LoggingCaptureHandler instance since it's expensive to create
2020-05-18 23:16:51 +03:00
Ran Benita fe2febfff2
Merge pull request #7019 from bluetech/rm-pyobj_property
Remove pyobj_property helper, inline it instead
2020-05-18 23:13:52 +03:00
Ran Benita 694fdc6554 Remove pyobj_property helper, inline it instead
It doesn't save much code but adds indirection which makes it a bit
harder to follow and to type.
2020-05-18 20:54:11 +03:00
Bruno Oliveira ad3169428b Remove unused Function.__init__ 'args' parameter 2020-05-18 14:30:48 -03:00
Daniel Hahler 8b9b81c3c0
Function: use `originalname` in `_getobj` and make it default to `name` (#7035) 2020-05-18 14:08:47 -03:00
Ran Benita d2d11a8bdc logging: reuse LoggingCaptureHandler instance since it's expensive to create
Previously, a LoggingCaptureHandler was instantiated for each test's
setup/call/teardown which turns out to be expensive.

Instead, only keep one instance and reset it between runs.
2020-05-18 11:27:50 +03:00
Ran Benita e27228a4e4
Merge pull request #7224 from bluetech/logging-simplifications
logging: some simplifications/cleanups
2020-05-18 00:15:59 +03:00
Ran Benita f71ec8cc90 logging: order hookimpl's in chronological order
Makes it easier to understand what's going on.
2020-05-17 21:41:38 +03:00
Ran Benita 3f8200676f logging: remove deprecated --no-print-logs option/ini
This option was deprecated in 5.4.0 and was marked for removal in 6.0.0.
2020-05-17 21:41:38 +03:00
Ran Benita bd5e3f042d logging: move log_file_handler cleanup from sessionend to unconfigure
It is set-up in configure, so match it.
2020-05-17 21:41:38 +03:00
Ran Benita 43c465c9bf logging: use dummy handler when CLI logging is disabled instead of None
This makes the code cleaner by removing conditionals and making the CLI
and file logging completely analogous.

Doesn't affect performance.
2020-05-17 21:41:38 +03:00
Ran Benita bd657bab3f logging: don't use _runtest_for for the pytest_log* hooks
The logstart/logreport/logfinish hooks don't need the stuff in
_runtest_for. The test capturing catching_logs call is irrelevant for
them, and the item-conditional sections are gone.
2020-05-17 21:41:38 +03:00
Ran Benita b13af52bbe logging: call set_when() in a consistent manner 2020-05-17 21:41:38 +03:00
Ran Benita 075903dafa logging: simplify log-file handling
- Instead of making it optional, always set up a handler, but possibly
  going to /dev/null. This simplifies the code by removing a lot of
  conditionals. It also can replace the NullHandler() we already add.

- Change `set_log_path` to just change the stream, instead of recreating
  one. Besides plugging a resource leak, it enables the next item.

- Remove the capturing_logs from _runtest_for, since it sufficiently
  covered by the one in pytest_runtestloop now, which wraps all other
  _runtest_for calls.

The first item alone would have had an adverse performance impact, but
the last item removes it.
2020-05-17 21:41:37 +03:00
Ran Benita e48ac692de logging: optimize catching_logs slightly
Remove usage of `@contextmanager` as it is a bit slower than
hand-rolling, and also disallows re-entry which we want to use.

Removing protections around addHandler()/removeHandler(), because
logging already checks that internally.
2020-05-17 20:42:06 +03:00