Commit Graph

2059 Commits

Author SHA1 Message Date
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
Ran Benita eceb28e4be logging: set formatter on handler creation, not in catching_logs
Conceptually it doesn't check per catching_logs (and catching_logs
doesn't restore the older one either). It is just something that is
defined for each handler once.
2020-05-17 20:42:06 +03:00
Ran Benita ce0f218793 logging: yield from _runtest_for instead of contextmanager
Avoid the slight overhead of contextmanager.
2020-05-17 20:42:06 +03:00
Ran Benita 9effbe7425 logging: inline _runtest_for_main into _runtest_for
This avoids a little bit of overhead, and makes the code a bit clearer
too.
2020-05-17 20:42:06 +03:00
Ran Benita ac6c02f1e2 logging: use item's store for private attributes
This makes things type-safe and properly private.
2020-05-17 20:42:05 +03:00
Bruno Oliveira c26f389c09 Refactor handling of non-top-level pytest_plugins handling
Decided to move the 'if' logic together with the error message, as this leaves
the _importconftest method cleaner.
2020-05-17 11:26:30 -03:00
Bruno Oliveira 9e1e7fcabe Use a nice string repr for ConftestImportFailure
The default message is often hard to read:

    E   _pytest.config.ConftestImportFailure: (local('D:\\projects\\pytest\\.tmp\\root\\foo\\conftest.py'), (<class 'RuntimeError'>, RuntimeError('some error',), <traceback object at 0x000001CCC3E39348>))

Using a shorter message is better:

    E   _pytest.config.ConftestImportFailure: RuntimeError: some error (from D:\projects\pytest\.tmp\root\foo\conftest.py)

And we don't really lose any information due to exception chaining.
2020-05-17 11:26:30 -03:00
Bruno Oliveira 5eaebc1900 Remove one of the tracebacks from conftest import failures
This removes the KeyError from the traceback chain when an
conftest fails to import:

    return self._conftestpath2mod[key]
    E   KeyError: WindowsPath('D:/projects/pytest/.tmp/root/foo/conftest.py')

    During handling of the above exception, another exception occurred:
    ...
        raise RuntimeError("some error")
    E   RuntimeError: some error

    During handling of the above exception, another exception occurred:
    ...
    E   _pytest.config.ConftestImportFailure: (...)

By slightly changing the code, we can remove the first chain, which is often
very confusing to users and doesn't help with anything.

Fix #7223
2020-05-17 11:26:02 -03:00
Bruno Oliveira c5b367b4f4 Package.name now contains only basname of the package
Previously it contained the entire path, which made '-k' match
against any name in the full path of the package.

Fix #7040
2020-05-16 15:04:07 -03:00
Daniel Hahler 3d3b9511fd -k should not match session name
Fixes https://github.com/pytest-dev/pytest/issues/7040.
2020-05-16 14:15:57 -03:00
Bruno Oliveira f506682abe
Merge pull request #6919 from nicoddemus/backport-6914 2020-05-16 12:42:15 -03:00
Daniel Hahler d530d70128 Fix regressions with `--lf` plugin
Only filter with known failures, and explicitly keep paths of passed
arguments.

This also displays the "run-last-failure" status before collected files,
and does not update the cache with "--collect-only".

Fixes https://github.com/pytest-dev/pytest/issues/6968.
2020-05-15 18:35:38 -03:00
Ran Benita f0f552d60c
Merge pull request #6283 from felixn/master
Create LogCaptureHandler if necessary (closes #6240)
2020-05-15 09:13:57 +03:00
Ran Benita 2ac28f6c65
Merge pull request #7205 from lancelote/7126
Issue 7126 - "saferepr" to avoid BytesWarning when using --setup-show
2020-05-14 16:04:22 +03:00
Felix Nieuwenhuizen 4dfc461036 Create LogCaptureHandler if necessary (closes #6240) 2020-05-13 20:38:14 +02:00
Ran Benita c714f05ad7 mark: reuse compiled expression for all items in -k/-m
The previous commit made this possible, so utilize it.

Since legacy.py becomes pretty bare, I inlined it into __init__.py. I'm
not sure it's really "legacy" anyway!

Using a simple 50000 items benchmark with `--collect-only -k nomatch`:

Before (two commits ago):

   ======================== 50000 deselected in 10.31s =====================
         19129345 function calls (18275596 primitive calls) in 10.634 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    2.270    2.270 __init__.py:149(pytest_collection_modifyitems)
        1    0.036    0.036    2.270    2.270 __init__.py:104(deselect_by_keyword)
    50000    0.055    0.000    2.226    0.000 legacy.py:87(matchkeyword)

After:

   ======================== 50000 deselected in 9.37s =========================
         18029363 function calls (17175972 primitive calls) in 9.701 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    1.394    1.394 __init__.py:239(pytest_collection_modifyitems)
        1    0.057    0.057    1.393    1.393 __init__.py:162(deselect_by_keyword)

The matching itself can be optimized more but that's a different story.
2020-05-12 12:55:37 +03:00
Ran Benita 622c4ce02e mark/expression: support compiling once and reusing for multiple evaluations
In current pytest, the same expression is matched against all items. But
it is re-parsed for every match.

Add support for "compiling" an expression and reusing the result. Errors
may only occur during compilation.

This is done by parsing the expression into a Python `ast.Expression`,
then `compile()`ing it into a code object. Evaluation is then done using
`eval()`.

Note: historically we used to use `eval` directly on the user input --
this is not the case here, the expression is entirely under our control
according to our grammar, we just JIT-compile it to Python as a
(completely safe) optimization.
2020-05-12 12:53:12 +03:00
Ran Benita 645aaa728d python_api: reduce scope of a `except BaseException` in ApproxNumpy
I'm not sure if it can even raise at all, but catching BaseException
would swallow ctrl-C and such and is definitely inappropriate here.
2020-05-12 12:07:56 +03:00
Ran Benita 23c9856857 Remove no longer needed noqa's 2020-05-12 09:29:47 +03:00
Ran Benita 59a12e9ab3 Replace bare `except`s with `except BaseException`
Mostly I wanted to remove uses of `noqa`.

In Python 3 the two are the same.
2020-05-12 09:29:47 +03:00
Ran Benita c4f9eaa5de mark: deprecate a couple undocumented -k syntaxes
The `-k '-expr'` syntax is an old alias to `-k 'not expr'`. It's also
not a very convenient to have syntax that start with `-` on the CLI.
Deprecate it and suggest replacing with `not`.

---

The `-k 'expr:'` syntax discards all items until the first match and
keeps all subsequent, e.g. `-k foo` with

    test_bar
    test_foo
    test_baz

results in `test_foo`, `test_baz`. That's a bit weird, so deprecate it
without a replacement. If someone complains we can reconsider or devise
a better alternative.
2020-05-11 16:07:52 +03:00
Pavel Karateev 7b196747dd Use saferepr for all types 2020-05-10 12:47:26 +03:00
Pavel Karateev 903e2ab6ee Fix #7126 - saferepr for bytes params
bytes parametrize parameters cause error when --setup-show is used
and Python is called with -bb flag
2020-05-09 13:57:17 +03:00
Bruno Oliveira 5dd987e10f
Merge pull request #6999 from bluetech/simplify-fixture-compat 2020-05-08 08:06:35 -03:00
Bruno Oliveira 9657798c12
Merge pull request #7158 from CarycaKatarzyna/issue_7076 2020-05-08 07:56:03 -03:00
Ran Benita 857b5c9ccd
Merge pull request #7185 from bluetech/sigpipe
Handle SIGPIPE/BrokenPipeError in pytest's CLI
2020-05-08 13:32:34 +03:00
Ran Benita 73448f265d Handle EPIPE/BrokenPipeError in pytest's CLI
Running `pytest | head -1` and similar causes an annoying error to be
printed to stderr:

    Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
    BrokenPipeError: [Errno 32] Broken pipe

(or possibly even a propagating exception in older/other Python versions).

The standard UNIX behavior is to handle the EPIPE silently. To
recommended method to do this in Python is described here:
https://docs.python.org/3/library/signal.html#note-on-sigpipe

It is not appropriate to apply this recommendation to `pytest.main()`,
which is used programmatically for in-process runs. Hence, change
pytest's entrypoint to a new `pytest.console_main()` function, to be
used exclusively by pytest's CLI, and add the SIGPIPE code there.

Fixes #4375.
2020-05-08 12:51:02 +03:00
Anthony Sottile b238845d0f Fix _is_setup_py for files encoded differently than locale 2020-05-07 13:14:58 -07:00
Ran Benita 65963d2066 warnings: speed up work done in catch_warnings_for_item()
When setting up the warnings capture, filter strings (with the general
form `action:message:category:module:line`) are collected from the
cmdline, ini and item and applied. This happens for every test and other
cases.

To apply a string it needs to be parsed into a tuple, and it turns out
this is slow. Since we already vendor the parsing code from Python's
warnings.py, we can speed it up by caching the result. After splitting
the parsing part from the applying part, the parsing is pure and is
straightforward to cache.

An alternative is to parse ahead of time and reuse the result, however
the caching solution turns out cleaner and more general in this case.

On this benchmark:

    import pytest
    @pytest.mark.parametrize("x", range(5000))
    def test_foo(x): pass

Before:

============================ 5000 passed in 14.11s =============================
         14365646 function calls (13450775 primitive calls) in 14.536 seconds

After:

============================ 5000 passed in 13.61s =============================
         13290372 function calls (12375498 primitive calls) in 14.034 seconds
2020-05-07 12:19:13 +03:00
Ran Benita 81da5dac48
Merge pull request #7122 from bluetech/matcher-parser
Stop using Python's eval() for -m and -k
2020-05-07 09:23:29 +03:00
Bruno Oliveira 6c2d358918
Merge pull request #7135 from pytest-dev/terminalwriter 2020-05-06 18:26:44 -03:00
Bruno Oliveira 4d439760ad
Merge pull request #7168 from nicoddemus/saferepr-getattr-fail-7145 2020-05-06 17:57:38 -03:00
Ran Benita d16ae0bbdc
Merge pull request #7171 from bluetech/code-import-cycles
code: fix import cycles between code.py and source.py
2020-05-06 18:15:32 +03:00
Ran Benita 89eee90b5f python: optimize PythonCollector.collect 2020-05-06 12:05:04 +03:00
Ran Benita b90f34569f nodes: micro-optimize Node attribute access 2020-05-06 11:58:30 +03:00
Ran Benita 5702c86f4c nodes: micro-optimize hash(node)
Turns out it's called alot, and saving the function call makes it
faster.
2020-05-06 11:58:30 +03:00
Ran Benita fcc473ab1c Use dict instead of OrderedDict on Python 3.7
OrderedDict is quite a bit heavier than just a dict.
2020-05-06 11:58:28 +03:00
Ran Benita 69143fe5b0 code: fix import cycles between code.py and source.py
These two files were really intertwined. Make it so code.py depends on
source.py without a reverse dependency.

No functional changes.
2020-05-06 11:01:32 +03:00
Bruno Oliveira d0022b5a13 'saferepr' handles classes with broken __getattribute__
Fix #7145
2020-05-05 19:22:39 -03:00
Ran Benita 94400a68b4 terminal: fix non-deterministic warning summary order in Python 3.5
In Python 3.5, collections.Counter() does not preserve insertion order.
2020-05-05 23:08:44 +03:00
Ran Benita 4b91617002
Merge pull request #7020 from blueyed/fix-warnings-summary
Fix warnings summary
2020-05-05 21:58:57 +03:00
Ran Benita b4be6cd4b7
Merge pull request #6765 from blueyed/capture-refactor-1
Refactor Capture classes: move/rename CaptureIO classes
2020-05-05 21:46:18 +03:00
Daniel Hahler 8cae78a18b Fix warnings summary
- replace "tests with warnings" with just warnings: they a) might not
  come from a test in the first place, and b) a single test might have
  multiple warnings.
- fix usage of (unused) argument to `collapsed_location_report`

Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-05-05 21:40:34 +03:00
Ran Benita d7d627b1e8
Merge pull request #7064 from blueyed/fix-_printcollecteditems-doc-upstream
Fix/improve printing of docs for collected items
2020-05-05 21:31:21 +03:00
Daniel Hahler 7647d1c836 Move Capture classes from compat to capture and improve naming
Move {Passthrough,CaptureIO} to capture module, and rename Passthrough
-> Tee to match the existing terminology.

Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-05-05 21:24:59 +03:00
Ran Benita 46d768503e
Merge pull request #6839 from blueyed/typing-get_dirs_from_args-parseconfig
typing: get_dirs_from_args, parseconfig
2020-05-05 21:11:26 +03:00
Ran Benita 85732e2b08
Merge pull request #6993 from blueyed/doc-pytest_collection-upstream
[WIP] doc: pytest_collection: has to set `session.items`
2020-05-05 21:05:56 +03:00
Bruno Oliveira 16a44823eb Use reportinfo() instead of location in skipping message 2020-05-04 19:50:40 -03:00
Katarzyna 402ee6fb9d Relative path to invocationdir instead rootdir. 2020-05-03 22:56:38 +02:00
Bruno Oliveira 80e5098408
Merge pull request #7155 from kerizane/make_numbered_dir 2020-05-03 09:48:36 -03:00
Keri Volans 678440e46d 7018: Use internal version of make_numbered_dir 2020-05-03 10:45:06 +01:00
Bruno Oliveira 5c2e96c0e6 Fix cleanup functions not being invoked on test failures
Also delay calling tearDown() when --pdb is given, so users still have
access to the instance variables (which are usually cleaned up during tearDown())
when debugging.

Fix #6947
2020-05-02 15:26:55 -03:00
Bruno Oliveira 2b51ed46d5
Merge pull request #7153 from nicoddemus/xunit-warning-update 2020-05-02 13:31:34 -03:00
Bruno Oliveira 095a195d71 Improve docs about junit_family warning message
From discussion in #6178
2020-05-02 13:01:15 -03:00
Bruno Oliveira 0b78983197
Merge pull request #7141 from bluetech/rm-nonzero 2020-05-02 10:00:35 -03:00
Bruno Oliveira e3643751bc
Merge pull request #7144 from nicoddemus/async-testcase-7110 2020-05-01 16:44:10 -03:00
Bruno Oliveira fd2f172258 Let unittest frameworks deal with async functions
Instead of trying to handle unittest-async functions in pytest_pyfunc_call,
let the unittest framework handle them instead.

This lets us remove the hack in pytest_pyfunc_call, with the upside that
we should support any unittest-async based framework.

Also included 'asynctest' as test dependency for py37-twisted, and renamed
'twisted' to 'unittestextras' to better reflect that we install 'twisted' and
'asynctest' now.

This also fixes the problem of cleanUp functions not being properly called
for async functions.

Fix #7110
Fix #6924
2020-05-01 15:10:28 -03:00
Bruno Oliveira 7f5978c34c Allow File.from_parent to forward custom parameters to the constructor 2020-05-01 11:00:52 -03:00
Ran Benita a718ad6363 Stop using Python's eval() for -m and -k
Previously, the expressions given to the `-m` and `-k` options were
evaluated with `eval`. This causes a few issues:

- Python keywords cannot be used.

- Constants like numbers, None, True, False are not handled correctly.

- Various syntax like numeric operators and `X if Y else Z` is supported
  unintentionally.

- `eval()` is somewhat dangerous for arbitrary input.

- Can fail in many ways so requires `except Exception`.

The format we want to support is quite simple, so change to a custom
parser. This fixes the issues above, and gives us full control of the
format, so can be documented comprehensively and even be extended in the
future if we wish.
2020-05-01 12:59:06 +03:00
Ran Benita 409ffcef17 Remove a couple Python 2 __nonzero__ definitions
It's called __bool__ in Python 3.
2020-05-01 11:41:21 +03:00
Ran Benita d8558e87c5 terminalwriter: clean up markup function a bit 2020-04-30 16:44:03 +03:00
Ran Benita 414a87a53f config/argparsing: use our own get_terminal_width() 2020-04-30 16:44:03 +03:00
Ran Benita d5584c7207 terminalwriter: compute width_of_current_line lazily
Currently this property is computed eagerly, which means
get_line_width() is computed on everything written, but that is a slow
function.

Compute it lazily, so that get_line_width() only runs when needed.
2020-04-30 16:44:03 +03:00
Ran Benita dd32c72ff0 terminalwriter: remove unused property chars_on_current_line 2020-04-30 16:44:03 +03:00
Ran Benita 1bc4170e63 terminalwriter: don't flush implicitly; add explicit flushes
Flushing on every write is somewhat expensive.

Rely on line buffering instead (if line buffering for stdout is
disabled, there must be some reason...), and add explicit flushes when
not outputting lines.

This is how regular `print()` e.g. work so should be familiar.
2020-04-30 16:44:03 +03:00
Ran Benita d9b43647b7 terminalwriter: inline function _update_chars_on_current_line 2020-04-30 16:44:03 +03:00
Ran Benita 8e04d35a33 terminalwriter: remove unneeded hasattr use 2020-04-30 16:44:03 +03:00
Ran Benita e8fc5f99fa terminalwriter: add type annotations 2020-04-30 16:44:03 +03:00
Ran Benita f6564a548a terminalwriter: remove win32 specific code in favor of relying on colorama
On Windows we already depend on colorama, which takes care of all of
this custom code on its own.
2020-04-30 16:44:03 +03:00
Ran Benita 8d2d1c40f8 terminalwriter: inline function _escaped
Doesn't add much.
2020-04-30 16:44:03 +03:00
Ran Benita 66ee755649 terminalwriter: remove TerminalWriter's stringio argument
Had a mark indicating it should be removed, and I agree, it's better to
just use the `file` argument.
2020-04-30 16:44:02 +03:00
Ran Benita 94a57d2353 io: combine _io.TerminalWriter and _io.terminalwriter.TerminalWriter
Previously it extended an external type but now it come move to the type
itself.
2020-04-30 16:44:02 +03:00
Ran Benita dac05ccd9a terminalwriter: remove support for passing callable as file in TerminalWriter
Not used.
2020-04-30 16:44:02 +03:00
Ran Benita 0528307ebf terminalwriter: remove unused function TerminalWriter.reline 2020-04-30 16:44:02 +03:00
Ran Benita a6819726cd terminalwriter: remove unused function ansi_print 2020-04-30 16:44:02 +03:00
Ran Benita b6cc90e0af terminalwriter: remove support for writing bytes directly
It is not used and slows things down.
2020-04-30 16:44:02 +03:00
Ran Benita 9a59970cad terminalwriter: optimize get_line_width() a bit
This function is called a lot when printing a lot of text, and is very
slow -- this speeds it up a bit.
2020-04-30 16:44:02 +03:00
Ran Benita 6c1b6a09b8 terminalwriter: simplify get_terminal_width()
The shutil.get_terminal_size() handles everything this did already.
2020-04-30 16:44:02 +03:00
Ran Benita c749e44efc terminalwriter: remove custom win32 screen width code
Python 3 does this on its own so we can use the shared code:
bcf2b59fb5
2020-04-30 16:44:02 +03:00
Ran Benita 1d596b27a7 terminalwriter: move Win32ConsoleWriter definition under win32 conditional
This way non-Windows platforms skip it. It also uses things defined
inside the `if`.
2020-04-30 16:44:02 +03:00
Ran Benita 5e2d820308 terminalwriter: fix lints 2020-04-30 16:44:02 +03:00
Ran Benita 3014d9a3f7 terminalwriter: auto-format 2020-04-30 16:43:55 +03:00
Ran Benita 276405a039 terminalwriter: vendor TerminalWriter from py
Straight copy from py 1.8.1. Doesn't pass linting yet.
2020-04-30 16:43:54 +03:00
Ran Benita c72a1b2933 config: replace usage of py.io.dupfile
As part of the effort to remove uses of `py`.
2020-04-29 18:04:37 +03:00
Ran Benita e5d6e58625
Merge pull request #7130 from bluetech/cacheprovider-nf-set
cacheprovider: speed up NFPlugin when --nf is not enabled
2020-04-29 17:28:20 +03:00
Ran Benita 4a42afdc2f cacheprovider: speed up NFPlugin when --nf is not enabled
The code used an O(n^2) loop. Replace list with set to make it O(n).

For backward compatibility the filesystem cache still remains a list.

On this test:

    import pytest
    @pytest.mark.parametrize("x", range(5000))
    def test_foo(x): pass

run with `pytest --collect-only`:

Before: 0m1.251s
After:  0m0.921s
2020-04-29 13:02:38 +03:00
Ran Benita 9bf3efb8e9
Merge pull request #7120 from bluetech/update-dev
pre-commit: update some tool revisions
2020-04-25 23:07:15 +03:00
Ran Benita 3cd97d50f9 pre-commit: update pyupgrade 1.18.0 -> 2.2.1 2020-04-24 21:57:38 +03:00
Ran Benita 38c9d59ddc pre-commit: update blacken-docs 1.0.0 -> 1.6.0 2020-04-24 21:53:37 +03:00
Ran Benita 289e6c1d36
Update src/_pytest/deprecated.py
Co-Authored-By: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de>
2020-04-24 21:37:08 +03:00
Ran Benita 907e29a47b fixtures: deprecate pytest._fillfuncargs function
This function is exposed and kept alive for the oejskit plugin which is
abandoned and no longer works with recent plugins, so let's prepare to
completely remove it.
2020-04-24 18:54:46 +03:00
Ran Benita 7d5f5a8785
Merge pull request #7050 from blueyed/fix-doc
doc: internal: remove references to old "newinterpret" module
2020-04-17 17:11:31 +03:00
Ran Benita 731c340be6
Merge pull request #7058 from blueyed/doc-store
doc: minor fixes for Store
2020-04-17 17:10:35 +03:00
Katarzyna Król 7789b51acb
Issue 4677 - always relative path in skip report (#6953) 2020-04-17 08:28:36 +03:00
Simon K de6c28ed1f
Improve error handling around yieldctx fixtures which do not yield a value (#7083) 2020-04-15 12:17:13 +03:00
Ran Benita 9ddf38369d
Merge pull request #7069 from bluetech/faulthandler-doc-windows
Remove note saying faulthandler_timeout is not available on Windows
2020-04-14 10:24:28 +03:00
Simon K f479cbce10
Document pytester fixtures so --fixtures makes more sense (#7080) 2020-04-13 20:58:50 +03:00