Commit Graph

12271 Commits

Author SHA1 Message Date
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 e40bf1d1da Add a changelog for TerminalWriter changes 2020-04-30 16:44:03 +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 bafc9bd58b testing: merge code/test_terminal_writer.py into io/test_terminalwriter.py 2020-04-30 16:44:03 +03:00
Ran Benita 0e36596268 testing/io: port TerminalWriter tests from py 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 be68496440
Merge pull request #7134 from bluetech/rm-dupfile
config: replace usage of py.io.dupfile
2020-04-30 14:07:52 +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 077d1c3502
Merge pull request #7129 from bluetech/testing-cache-writefail-warning
testing: fix warning issued by test_cache_writefail_cachfile_silent
2020-04-29 16:00:43 +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
Anthony Sottile dd49812dae
Merge pull request #7131 from ArtyomKaltovich/patch-1
update doctests.rst regarding issue #7116
2020-04-28 13:59:25 -07:00
ArtyomKaltovich bef263ee76
update doctests.rst regarding issue #7116
https://github.com/pytest-dev/pytest/issues/7116
2020-04-28 23:04:58 +03:00
Ran Benita 49e50d3106 testing: fix warning issued by test_cache_writefail_cachfile_silent
Remove this message which was shown in the warning summary of pytest's
own testsuite:

    testing/test_cacheprovider.py::TestNewAPI::test_cache_writefail_cachfile_silent
      testing/test_cacheprovider.py:40: PytestCacheWarning: could not create cache path /tmp/pytest-of-ran/pytest-2/test_cache_writefail_cachfile_silent0/.pytest_cache/v/test/broken
        cache.set("test/broken", [])
2020-04-28 22:49:00 +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 9828cfa339
Merge pull request #7117 from bluetech/deprecate-fillfuncargs-v2
fixtures: deprecate pytest._fillfuncargs function
2020-04-24 22:59:06 +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 23881ad592 pre-commit: update pre-commit-hooks 2.2.3 -> 2.5.0 2020-04-24 21:53:40 +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 cbca9f1def
Merge pull request #7118 from bluetech/ignore-collect-directory-warning
testing: avoid pytest_collect_directory message in warning summary
2020-04-24 21:34:29 +03:00
Ran Benita e269407e65 testing: avoid pytest_collect_directory message in warnings summary
Currently this test issues a warning which is displayed in the warning
summary (of pytest's own test suite):

  testing/acceptance_test.py::TestGeneralUsage::test_early_skip
    /tmp/pytest-of-ran/pytest-396/test_early_skip0/conftest.py:2: PytestDeprecationWarning: The pytest_collect_directory hook is not working.
    Please use collect_ignore in conftests or pytest_collection_modifyitems.
      def pytest_collect_directory():

I think the filter was meant to be `ignore` in the first place, and not
`always` which is not a valid action AFAIK.
2020-04-24 19:06:31 +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 9f4e680403
Merge pull request #7089 from bluetech/rm-tox-pypy
Remove pypy (2) environment from tox.ini
2020-04-14 15:42:39 +03:00