Commit Graph

12725 Commits

Author SHA1 Message Date
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
Florian Dahlitz 62d3577435
Add note about --strict and --strict-markers to references 2020-05-22 16:33:50 +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
Bruno Oliveira c98bc4cd3d
Merge pull request #7234 from mcsitter/master 2020-05-20 17:51:06 -03:00
mcsitter fa6a13a7cc Updated compatible python versions
As indicated on pypi and in the README pytest supports python version 3.8 and 3.9. The documentation should match.
2020-05-20 22:41:52 +02:00
Ran Benita 1af3c115a6
Merge pull request #7200 from bluetech/contributing-backporting
CONTRIBUTING: add section about backporting fixes to patch releases
2020-05-20 20:21:23 +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
Ran Benita b337a9a66d CONTRIBUTING: add section about backporting fixes to patch releases 2020-05-20 19:29:13 +03:00
Bruno Oliveira 0a03217903
Merge pull request #7046 from blueyed/k-skip-session-upstream 2020-05-19 20:09:36 -03:00
Bruno Oliveira 88214310af
Merge pull request #6817 from blueyed/argparsing-_split_lines-upstream 2020-05-19 20:06:51 -03:00
Bruno Oliveira 5a2c69f150 Add CHANGELOG for #6817 2020-05-19 19:35:18 -03:00
Daniel Hahler 35d136161a add test
Fixes the test to not match e.g. hypothesis (ref: bdde2ac28).

Conflicts:
	testing/test_helpconfig.py
2020-05-19 19:34:08 -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 d05ef61e95
Merge pull request #6840 from blueyed/test_source_with_decorator 2020-05-19 19:30:23 -03:00
Bruno Oliveira 55099e57c3 Add requested comment as per review 2020-05-19 19:20:41 -03:00
Daniel Hahler b98a182aa1 (no) coverage 2020-05-19 19:20:41 -03:00
Daniel Hahler 61180eec93 Test behavior of Source with regard to decorators
Unlinke `inspect.getsource` it does not unwrap functions.
2020-05-19 19:20:41 -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
Katrin Leinweber 9bf28853bf
doc: highlight difference between progress percentage & code coverage (#6686) 2020-05-18 20:51:22 +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
Anthony Sottile 9310d67773
Merge pull request #7003 from blueyed/tests-reload-upstream
tests: revisit tests for removed load_module
2020-05-17 14:36:13 -07:00
Daniel Hahler 18bc706fdc tests: revisit tests for removed load_module
The tests came via c629f6b18 and c61ff31ffa.
The fixes from there are kind of obsoleted by 4cd08f9 (moving to importlib),
but it makes sense to keep them as integration tests in general.
2020-05-17 14:16:43 -07: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 abbd97f917
Merge pull request #7222 from nicoddemus/remove-key-error-conftest-exception 2020-05-17 11:43:43 -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