Commit Graph

2093 Commits

Author SHA1 Message Date
Ran Benita 113a860a1f argparsing: support parser.addini(type="paths") which returns pathlib.Paths 2021-05-07 09:58:51 +03:00
Tarcísio Fischer b7416f7abd
Suggest numpy testing module on pytest approx docs (#8615)
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Co-authored-by: Tarcisio Fischer <tarcisio@esss.co>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2021-05-04 23:08:41 -03:00
Anthony Sottile 915ff7640b Merge pull request #8632 from pytest-dev/release-6.2.4
Prepare release 6.2.4

(cherry picked from commit 15a45388fa272fde7b2b58254ca32c4998cb84f0)
2021-05-04 09:27:16 -07:00
Tarcísio Fischer 9d9b84d175
Improve pytest.approx error messages readability (Pull request) (#8429)
Improve pytest.approx error messages readability (Pull request)
2021-04-30 07:36:56 -03:00
Parth Patel 992c403fc8
Improve `iterparentnodeids` to consume `/` parts until the first `::` (#8577)
* Fix issue where TestCase.setUpClass is not called for test methods with a / in its name by checking if there is ::  before the selected / or any :: after. Also added a test case for this.

* removed print statement that was added

* Change iterparentnodeids to consume / parts until the first ::. Then consider ::. Tests were changed to reflect this.

* Update changelog/8509.improvement.rst

Co-authored-by: Ran Benita <ran@unusedvar.com>
2021-04-29 17:02:43 +03:00
Abdelrahman Elbehery 9078c3ce23
fix #8464 wrong root dir when -c is passed (#8537)
fix #8464 wrong root dir when -c is passed
2021-04-16 14:38:35 -03:00
hauntsaninja 8be1628042 Fix assertion rewriting on Python 3.10
Fixes https://github.com/pytest-dev/pytest/issues/8539

This seems to have been the result of https://bugs.python.org/issue43798
2021-04-11 15:42:42 -07:00
Tadeu Manoel b706a2c048
Fix error with --import-mode=importlib and modules containing dataclasses or pickle (#7870)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

Fixes #7856, fixes #7859
2021-04-05 17:10:03 -03:00
Ran Benita 5d2fad5362 Merge pull request #8519 from pytest-dev/release-6.2.3
Prepare release 6.2.3

(cherry picked from commit 724e22cb003031b88ae6fe50fa3eabdcc538a8bc)
2021-04-04 01:08:26 +03:00
Ran Benita c49100cef8 tmpdir: prevent using a non-private root temp directory
pytest uses a root temp directory named `/tmp/pytest-of-<username>`. The
name is predictable, and the directory might already exists from a
previous run, so that's allowed.

This makes it possible for my_user to pre-create
`/tmp/pytest-of-another_user`, thus giving my_user control of
another_user's tempdir.

Prevent this scenario by adding a couple of safety checks. I believe
they are sufficient.

Testing the first check requires changing the owner, which requires
root permissions, so can't be unit-tested easily, but I checked it
manually.
2021-04-03 23:42:53 +03:00
Ran Benita 1278f8b97e tmpdir: fix temporary directories created with world-readable permissions
(Written for a Unix system, but might be applicable to Windows as well).

pytest creates a root temporary directory under /tmp, named
`pytest-of-<username>`, and creates tmp_path's and other under it.
/tmp is shared between all users of the system.

This root temporary directory was created with 0o777&~umask permissions,
which usually becomes 0o755, meaning any user in the system could list
and read the files, which is undesirable.

Use 0o700 permissions instead. Also for subdirectories, because the root
dir is adjustable.
2021-04-03 23:42:53 +03:00
Miro Hrončok 778d2b2499 monkeypatch.syspath_prepend: Skip fixup_namespace_packages if pkg_resources not imported
Calling pkg_resources.fixup_namespace_packages() is only needed for packages
that use pkg_resources.declare_namespace() and hence they already imported
pkg_resources. When pkg_resources is not imported, we don't need to use it.

This avoids an unneeded runtime dependency on setuptools.
The code is tested by test_syspath_prepend_with_namespace_packages,
behavior should remain unchanged, hence no new test was added.

When people drop pkg_resources from sys.modules, they are on their own.
If someone has a actual use case making this valid to support,
they can come in and provide a test, a reference and a fix.
2021-04-01 20:24:21 +02:00
Bruno Oliveira a7416a535a Add classifier for Python 3.10 and CHANGELOG entry 2021-03-27 11:13:16 -03:00
Bruno Oliveira be8d63e33b Increase truncation threshold with -v, disable with -vv
Fix #6682
Fix #8403
2021-03-26 07:05:30 -03:00
Florian Bruhin bc055e8e69
Fix required_plugins with prereleases (#8469)
* Fix required_plugins with prereleases

Fixes #8456

* Fix existing tests

* Update changelog/8456.bugfix.rst

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2021-03-21 22:51:12 +01:00
Ran Benita b26d1bb18f cacheprovider: add cache.mkdir() as a Path-returning replacement to makedir()
It is not possible to change a return type in a compatible way, so a new
method is added.
2021-03-15 10:39:31 +02:00
Ran Benita db539ed2b0
Merge pull request #8437 from bluetech/rm-typevar-prefix
Remove `_` prefix from TypeVars, expose ExceptionInfo
2021-03-13 19:01:29 +02:00
Pierre Mourlanne af9f27a874
Approx decimal sequence mapping (#8422) 2021-03-13 16:01:23 +02:00
Ran Benita f2d65c85f4 code: export ExceptionInfo for typing purposes
This type is most prominent in `pytest.raises` and we should allow to
refer to it by a public name.

The type is not in a perfectly "exposable" state. In particular:

- The `traceback` property with type `Traceback` which is derived from
  the `py.code` API and exposes a bunch more types transitively. This
  stuff is *not* exported and probably won't be.

- The `getrepr` method which probably should be private.

But they're already used in the wild so no point in just hiding them
now.

The __init__ API is hidden -- the public API for this are the `from_*`
classmethods.
2021-03-13 15:59:44 +02:00
Daniele Procida d8695410a4 Added how-to and reference directories.
Moved various documents into subdirectories, how-to and
reference.

Updated multiple links to use `:ref:` instead of `:doc:`,
meaning that files can henceforth be moved around without
breaking references.
2021-03-11 22:13:01 +00:00
Anthony Sottile 79b03ce8db
Merge pull request #8411 from RonnyPfannschmidt/example-outcomes-check
fix bug in test for issue 519
2021-03-07 08:17:34 -08:00
Ronny Pfannschmidt 412fc001a0 fix bug in test for issue 519
assert the actual outcome and fix the filename
2021-03-07 15:01:39 +01:00
Ronny Pfannschmidt 22dad53a24 implement Node.path as pathlib.Path
* reorganize lastfailed node sort

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2021-03-06 21:32:03 +01:00
Alexandros Tzannes 19a2f7425d
Merge pull request #8399 from atzannes/master
closes #8394

Generated fixture names for unittest/xunit/nose should start with underscore
2021-03-04 22:45:57 +02:00
Florian Bruhin c14a9adba3
Fix skip signature (#8392)
* Fix test_strict_and_skip

The `--strict` argument was removed in #2552, but the removal wasn't
actually correct - see #1472.

* Fix argument handling in pytest.mark.skip

See #8384

* Raise from None

* Fix test name
2021-03-04 11:56:21 +01:00
Simon K b7f2d7ca61
Fixed an issue where `getpass.getuser()` contained illegal characters for file directories (#8365)
* retry writing pytest-of dir when invalid chars are in directory name

* add unit tests for getbasetemp() and changelog

* patch _basetemp & _given_basetemp for testing basetemp()

* Tweak changelog for #8317, tidy up comments
2021-02-25 08:28:57 +00:00
Florian Bruhin 54a154c86f Allow Class.from_parent to forward custom parameters to the constructor
Similarly to #7143, at work we have a project with a custom pytest.Class
subclass, adding an additional argument to the constructor.

All from_parent implementations in pytest accept and forward *kw, except
Class (before this change) and DoctestItem - since I'm not familiar with
doctest support, I've left the latter as-is.
2021-02-23 18:00:56 +01:00
Ronny Pfannschmidt 325d701f6e
Merge pull request #8248 from RonnyPfannschmidt/mixin-mro-position
alter the PyObjMixin to carry over typing information from Node
2021-02-07 18:44:44 +01:00
Ran Benita d358a060ad config/argparsing: use proper deprecations instead of ad-hoc DeprecationWarning
Proper for removing this in the next major pytest release.
2021-02-05 00:05:47 +02:00
Ran Benita 63ea727bc2
changelog: fix missing tick (#8295)
Messes with the rendering.
2021-01-29 16:21:25 +02:00
Maximilian Cosmo Sitter beda7a8a31
Add plugin list 2021-01-29 16:19:54 +02:00
Ran Benita 0b510bcc51
changelog: fix missing tick
Messes with the rendering.
2021-01-29 16:06:36 +02:00
Bruno Oliveira 6a5d47a243
Merge pull request #8260 from nicoddemus/faulthandler-mode-X-8258 2021-01-28 13:03:24 -03:00
Bruno Oliveira 2a890286f8 Merge pull request #8275 from pytest-dev/release-6.2.2
Prepare release 6.2.2

(cherry picked from commit 8220eca963472e7918ef7e108bdc1cd8ed155a4a)
2021-01-25 11:53:05 -03:00
Bruno Oliveira adc0f29b8f Always handle faulthandler stderr even if already enabled
It seems the code that would not install pytest's faulthandler support
if it was already enabled is not really needed at all, and even detrimental
when using `python -X dev -m pytest` to run Python in "dev" mode.

Also simplified the plugin by removing the hook class, now the hooks
will always be active so there's no need to delay the hook definitions anymore.

Fix #8258
2021-01-20 10:29:05 -03:00
Bruno Oliveira bda9ce4e0f
Merge pull request #8250 from daq-tools/fix-twisted-capture 2021-01-20 09:45:58 -03:00
Andreas Motl 9ba1821e91 Fix faulthandler for Twisted Logger when used with "--capture=no"
The Twisted Logger will return an invalid file descriptor since it is
not backed by an FD. So, let's also forward this to the same code path
as with `pytest-xdist`.
2021-01-18 17:51:08 +01:00
Ronny Pfannschmidt a9e43152bc alter the PyObjMixin to carry over typing information from Node
as PyObjMixin is always supposed to be mixed in the mro
before nodes.Node the behavior doesn't change,
but all the typing information carry over to help mypy.

extracted from #8037
2021-01-17 14:36:28 +01:00
Ran Benita 25e657bfc1 Deprecate raising unittest.SkipTest to skip tests during collection
It is not very clear why this code exists -- we are not running any
unittest or nose code during collection, and really these frameworks
don't have the concept of collection at all, and just raising these
exceptions at e.g. the module level would cause an error. So unless I'm
missing something, I don't think anyone is using this.

Deprecate it so we can eventually clear up this code and keep unittest
more tightly restricted to its plugin.
2021-01-15 00:05:33 +02:00
bengartner 8e00df4c4b
Add dot prefix if file makefile extension is invalid for pathlib (#8222) 2021-01-04 15:58:11 +02:00
Anton 48c9a96a03
Fix failing staticmethod tests if they are inherited (#8205)
* Fix failing staticmethod tests if they are inherited

* add comments, set default=None
2020-12-30 19:00:37 -08:00
Ran Benita 96ea867fec runner: export pytest.CallInfo for typing purposes
The type cannot be constructed directly, but is exported for use in type
annotations, since it is reachable through existing public API.

This also documents `from_call` as public, because at least
pytest-forked uses it, so we must treat it as public already anyway.
2020-12-26 21:38:37 +02:00
Ran Benita bd76042344 python: export pytest.Metafunc for typing purposes
The type cannot be constructed directly, but is exported for use in type
annotations, since it is reachable through existing public API.
2020-12-26 21:05:02 +02:00
Ran Benita d8d2df7e6f
Merge pull request #8174 from bluetech/py-to-pathlib-5
More py.path -> pathlib conversions
2020-12-26 15:01:07 +02:00
Ran Benita ca4effc822 Convert most of the collection code from py.path to pathlib 2020-12-22 21:09:36 +02:00
Ran Benita 92ba96b061 code: convert from py.path to pathlib 2020-12-22 21:08:25 +02:00
Ran Benita 6aa4d1c7ab mark: export pytest.MarkGenerator for typing purposes
The type cannot be constructed directly, but is exported for use in type
annotations, since it is reachable through existing public API.
2020-12-20 15:59:20 +02:00
Ran Benita 69c302479e mark: export pytest.MarkDecorator for typing purposes
The type cannot be constructed directly, but is exported for use in type
annotations, since it is reachable through existing public API.
2020-12-20 15:59:06 +02:00
Ran Benita 2ec372df8b mark: export pytest.Mark for typing purposes
The type cannot be constructed directly, but is exported for use in type
annotations, since it is reachable through existing public API.
2020-12-20 15:58:49 +02:00
Ran Benita 02e69e5cdc
Merge pull request #8152 from bluetech/empty-skip
terminal: fix "(<Skipped instance>)" skip reason in test status line
2020-12-17 12:58:00 +02:00
Ran Benita d46ecbc18b terminal: fix "(<Skipped instance>)" skip reason in test status line 2020-12-15 22:24:25 +02:00
Bruno Oliveira 56600414df Merge pull request #8149 from pytest-dev/release-6.2.1
Prepare release 6.2.1

(cherry picked from commit a566eb9c7085d7732127420bd7ce5ec1f7319fba)
2020-12-15 12:41:02 -03:00
Jakob van Santen 9ccbf5b899
python_api: handle array-like args in approx() (#8137) 2020-12-15 08:49:29 -03:00
Ran Benita 592b32bd69 hookspec: add pathlib.Path alternatives to py.path.local parameters in hooks
As part of the ongoing migration for py.path to pathlib, make sure all
hooks which take a py.path.local also take an equivalent pathlib.Path.
2020-12-15 00:34:23 +02:00
Bruno Oliveira 7e2e6630ad
Merge pull request #8123 from nicoddemus/import-mismatch-unc
Compare also paths on Windows when considering ImportPathMismatchError
2020-12-13 10:35:11 -03:00
Ran Benita 54a7356a9f Merge pull request #8130 from pytest-dev/release-6.2.0
Prepare release 6.2.0

(cherry picked from commit c475106f12ed87fe908544ff383c5205638c086d)
2020-12-12 23:23:19 +02:00
Pedro Algarvio b16c091253 Add `pytest_markeval_namespace` hook.
Add a new hook , `pytest_markeval_namespace` which should return a dictionary.
This dictionary will be used to augment the "global" variables available to evaluate skipif/xfail/xpass markers.

Pseudo example

``conftest.py``:

.. code-block:: python
   def pytest_markeval_namespace():
       return {"color": "red"}
``test_func.py``:

.. code-block:: python
   @pytest.mark.skipif("color == 'blue'", reason="Color is not red")
   def test_func():
       assert False
2020-12-12 17:41:37 +02:00
Bruno Oliveira 572dfcd160 Compare also paths on Windows when considering ImportPathMismatchError
On Windows, os.path.samefile returns false for paths mounted in UNC paths which
point to the same location.

I couldn't reproduce the actual case reported, but looking at the code it seems
this commit should fix the issue.

Fix #7678
Fix #8076
2020-12-12 08:54:49 -03:00
Katarzyna 612f157dbd Show reason for skipped test in verbose mode 2020-12-09 09:43:47 +02:00
Ran Benita e398c93884
Merge pull request #8055 from bluetech/unraisable
Add unraisableexception and threadexception plugins
2020-12-05 21:52:17 +02:00
Ran Benita 760a73c08c
Merge pull request #8017 from bluetech/typing-public-fixtures
Export types of builtin fixtures for type annotations
2020-12-05 21:51:20 +02:00
Prakhar Gurunani 3405c7e6a8
Add more info about skipping doctests (#8080)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-11-28 12:47:02 -03:00
Ran Benita d50df85e26 Add unraisableexception and threadexception plugins 2020-11-21 21:11:48 +02:00
Ran Benita d59a4996ae
Merge pull request #8057 from nicoddemus/changelog-links
Add links to some CHANGELOG entries
2020-11-21 20:47:27 +02:00
Maximilian Cosmo Sitter 0cef530d10
Add str() support to LineMatcher (#8050) 2020-11-21 20:45:20 +02:00
Bruno Oliveira 31021ac8d5 Add links to some CHANGELOG entries
While adding links to https://github.com/pytest-dev/pytest/pull/8052, noticed
a few more missing.
2020-11-21 11:05:54 -03:00
Simon K 52fef811c2
permit node to warn with any warning type, not just PytestWarning (#8052)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-11-21 10:49:17 -03:00
Petter Strandmark eda681af2b
Call Python 3.8 doClassCleanups (#8033) 2020-11-19 12:07:15 +02:00
Ran Benita 825b81ba52
Merge pull request #8014 from bluetech/pyc-pep552
assertion/rewrite: write pyc's according to PEP-552 on Python>=3.7
2020-11-14 23:38:45 +02:00
Ran Benita 1d532da49e assertion/rewrite: write pyc's according to PEP-552 on Python>=3.7
Python 3.7 changes the pyc format by adding a flags byte. Even though it
is not necessary for us to match it, it is nice to be able to read pyc
files we emit for debugging the rewriter.

Update our custom pyc files to use that format. We write flags==0
meaning we still use the mtime+size format rather the newer hash format.
2020-11-14 23:20:12 +02:00
Ran Benita f1e6fdcddb Export types of builtin fixture for type annotations
In order to allow users to type annotate fixtures they request, the
types need to be imported from the `pytest` namespace. They are/were
always available to import from the `_pytest` namespace, but that is
not guaranteed to be stable.

These types are only exported for the purpose of typing. Specifically,
the following are *not* public:

- Construction (`__init__`)
- Subclassing
- staticmethods and classmethods

We try to combat them being used anyway by:

- Marking the classes as `@final` when possible (already done).

- Not documenting private stuff in the API Reference.

- Using `_`-prefixed names or marking as `:meta private:` for private
  stuff.

- Adding a keyword-only `_ispytest=False` to private constructors,
  warning if False, and changing pytest itself to pass True. In the
  future it will (hopefully) become a hard error.

Hopefully that will be enough.
2020-11-13 11:25:09 +02:00
Ran Benita 66311ff702
Merge pull request #8022 from bluetech/doctest-init
main: fix only one doctest collected on pytest --doctest-modules __init__.py
2020-11-13 10:46:46 +02:00
Adam Johnson 39b2706f6a Add 'node_modules' to norecursedirs
Fixes #8023.
2020-11-11 01:52:18 +00:00
Ran Benita 265cc2cfec main: fix only one doctest collected on pytest --doctest-modules __init__.py
When --doctest-modules is used, an `__init__.py` file is not a `Package`
but a `DoctestModule`, but some collection code assumed that
`__init__.py` implies a `Package`. That code caused only a single test
to be collected in the scenario in the subject.

Tighten up this check to explicitly check for `Package`. There are
better solutions, but for another time.

Report & test by Nick Gates <nickgatzgates@gmail.com>.
2020-11-10 22:50:46 +02:00
Ran Benita e986d84466
Merge pull request #8006 from bluetech/export-MonkeyPatch
Export MonkeyPatch as pytest.MonkeyPatch
2020-11-09 11:45:38 +02:00
Ran Benita 6f13d1b03b Export MonkeyPatch as pytest.MonkeyPatch
We want to export `pytest.MonkeyPatch` for the purpose of
type-annotating the `monkeypatch` fixture. For other fixtures we export
in this way, we also make direct construction of them (e.g.
`MonkeyPatch()`) private. But unlike the others, `MonkeyPatch` is also
widely used directly already, mostly because the `monkeypatch` fixture
only works in `function` scope (issue #363), but also in other cases. So
making it private will be annoying and we don't offer a decent
replacement yet.

So, let's just make direct construction public & documented.
2020-11-09 11:28:15 +02:00
Hugo Martins 5b2e5e8a40
Improve summary stats when using '--collect-only' (#7875)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-11-08 11:45:10 -03:00
Ran Benita 4c0513bc18 fixtures: deprecate pytest.yield_fixture() 2020-11-07 17:06:40 +02:00
Bruno Oliveira 30287b49cd
Deprecate --strict (#7985)
Fix #7530
2020-11-06 09:48:20 +01:00
Ran Benita 7fb0ea3f68
Merge pull request #7956 from csernazs/fix-7951
Fix handling recursive symlinks
2020-10-31 18:59:50 +02:00
Cserna Zsolt 8a38e7a6e8 Fix handling recursive symlinks
When pytest was run on a directory containing a recursive symlink it failed
with ELOOP as the library was not able to determine the type of the
direntry:

src/_pytest/main.py:685: in collect
    if not direntry.is_file():
E   OSError: [Errno 40] Too many levels of symbolic links: '/home/florian/proj/pytest/tests/recursive'

This is fixed by handling ELOOP and other errors in the visit function in
pathlib.py, so the entries whose is_file() call raises an OSError with the
pre-defined list of error numbers will be exluded from the result.

The _ignore_errors function was copied from Lib/pathlib.py of cpython 3.9.

Fixes #7951
2020-10-31 17:40:56 +01:00
Ran Benita 1c18fb8ccc
Merge pull request #7553 from tirkarthi/namedtuple-diff
Add support to display field names in namedtuple diffs.
2020-10-31 15:02:31 +02:00
Karthikeyan Singaravelan 9a0f4e57ee Add support to display field names in namedtuple diffs. 2020-10-31 14:41:53 +02:00
Ran Benita 6cdae8ed40 pathlib: fix symlinked directories not followed during collection 2020-10-31 14:22:15 +02:00
Simon K 6cddeb8cb3
#7938 - [Plugin: Stepwise][Enhancements] Refactoring, smarter registration & --sw-skip functionality (#7939)
* adding --sw-skip shorthand for stepwise skip

* be explicit rather than implicit with default args for stepwise

* add constant for sw cache dir; only register plugin if necessary rather check check activity always;

* use str format; remove unused args in hooks

* assert cache upfront, allow stepwise to have a reference to the cache

* type hinting lf, skip, move literal strings into module constants

* convert parametrized option into a list

* add a sessionfinish hook for stepwise to keep backwards behaviour the same

* add changelog for #7938

* Improve performance of stepwise modifyitems & address PR feedback

* add test for stepwise deselected based on performance enhancements

* Apply suggestions from code review

* delete from items, account for edge case where failed_index = 0

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-10-30 19:13:06 +00:00
Bruno Oliveira b95991aeea
Merge pull request #7960 from nicoddemus/cherry-pick-release
Merge pull request #7958 from pytest-dev/release-6.1.2
2020-10-28 14:36:37 -03:00
Bruno Oliveira 5711ced250 Merge pull request #7958 from pytest-dev/release-6.1.2
Prepare release 6.1.2

(cherry picked from commit 1ed903e8fcbe60f8ce25b8911641059cd89d892b)
2020-10-28 14:23:09 -03:00
Vasilis Gerakaris a431310c0a
Increase temp dir deletion period to 3 days (#7914)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-10-28 08:23:35 -03:00
Ran Benita ca82214444 pytester: workaround issue causing spawn to crash or hang
In pytester tests, pytest stashes & restores the sys.modules for each
test. So if the test imports a new module, it is initialized anew each
time.

Turns out the readline module isn't multi-init safe, which causes
pytester.spawn to crash or hang. So preserve it as a workaround.
2020-10-25 16:31:47 +02:00
Ran Benita 470ea504e2 fixtures: fix quadratic behavior in the number of autouse fixtures
It turns out all autouse fixtures are kept in a global list, and thinned
out for a particular node using a linear scan of the entire list each
time.

Change the list to a dict, and only take the nodes we need.
2020-10-25 00:49:23 +03:00
Ran Benita afaabdda8c cacheprovider: fix some files in packages getting lost from --lf
--lf has an optimization where it skips collecting Modules (python
files) which don't contain failing tests. The optimization works by
getting the paths of all cached failed tests and skipping the collection
of Modules whose path is not included in that list.

In pytest, Package nodes are Module nodes with the fspath being the file
`<package dir>/__init__.py`. Since it's a Module the logic above
triggered for it, and because it's an `__init__.py` file which is
unlikely to have any failing tests in it, it is skipped, which causes
its entire directory to be skipped, including any Modules inside it with
failing tests.

Fix by special-casing Packages to never filter. This means entire
Packages are never filtered, the Modules themselves are always checked.
It is reasonable to consider an optimization which does filter entire
packages bases on parent paths etc. but this wouldn't actually save any
real work so is really not worth it.
2020-10-19 19:02:43 +03:00
Bruno Oliveira 69419cb700
New pytester fixture (#7854) 2020-10-12 12:13:06 -03:00
Charles Aracil 2e322f183c
ask for commit after changelog and authors file edit (#7878) 2020-10-09 16:10:54 +02:00
Kyle Altendorf 1630c37266 Added changelog/7872.doc.rst 2020-10-07 18:06:13 -04:00
Manuel Mariñez 13ddec9a00
Add alias clarification to deprecation warning (#7829)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-10-06 11:48:34 -03:00
Ran Benita fd74dd3dcb Merge pull request #7849 from pytest-dev/release-6.1.1
Prepare release 6.1.1

(cherry picked from commit 69d903260d39f50ef7233348e1521000710cc5ba)
2020-10-03 22:38:33 +03:00
Ran Benita 7705e5e624 doc: patch Sphinx to detect our `@final` for marking classes as `final`
Thanks to Dominic Davis-Foster for code & assistance.
2020-10-03 13:13:14 +03:00
Ran Benita a6a7ba57e0
Merge pull request #7817 from bluetech/fix-testpaths-bestrelpath2
terminal: fix crash in header reporting when absolute testpaths is used
2020-10-03 12:59:18 +03:00
Anthony Sottile 179f4326df py36+: drop python3.5 in CI and setup.cfg 2020-10-02 14:00:11 -07:00
Ran Benita b250c9d615
Merge pull request #7813 from bluetech/findpaths-confusion
findpaths: fix regression causing incorrect rootdir to be determined
2020-09-30 13:21:18 +03:00
Ran Benita 61f80a783a terminal: fix crash in header reporting when absolute testpaths is used
Regressed in 6.1.0 in 62e249a1f9.
The `x` is an `str` but is expected to be a `pathlib.Path`. Not caught
by mypy because `config.getini()` returns `Any`.

Fix by just removing the `bestrelpath` call:

- testpaths are always relative to the rootdir, it thus would be very
  unusual to specify an absolute path there.

- The code was wrong even before the regression: `py.path.local`'s
  `bestrelpath` function expects a `py.path.local`, not an `str`. But it
  had some weird `try ... except AttributeError` fallback which just
  returns the argument, i.e. it was a no-op. So there is no behavior
  change.

- It seems reasonable to me to just print the full path if that's what
  the ini specifies.
2020-09-29 15:23:47 +03:00
Ran Benita cd67c2a8cf
Merge pull request #7802 from bluetech/bump-attrs
Bump attrs requirement from >=17.4.0 to >=19.2.0
2020-09-28 19:30:58 +03:00
Ran Benita 4a9192f727 findpaths: fix regression causing incorrect rootdir to be determined
When switching from py.path.local to pathlib (70f3ad1c1f),
`local.parts(reverse=True)` was translated incorrectly, leading to the
wrong rootdir being determined in some non-trivial cases where parent
directories have config files as well.
2020-09-28 19:13:01 +03:00
Jakob van Santen 91fa11bed0
python_api: let approx() take nonnumeric values (#7710)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-09-28 12:17:23 -03:00
Ran Benita 32bb8f3a63 Bump attrs requirement from >=17.4.0 to >=19.2.0
This allows us to remove the `ATTRS_EQ_FIELD` thing which is causing
some annoyance.
2020-09-27 13:17:59 +03:00
Ran Benita 19c78ab574 Merge pull request #7797 from pytest-dev/release-6.1.0
Prepare release 6.1.0

(cherry picked from commit 08a1ab3a8acdfdeffd8f07058b44743df1d90150)
2020-09-26 21:11:48 +03:00
Ran Benita d3c746eb8e changelog: some consistency cleanups 2020-09-26 20:04:17 +03:00
Ran Benita a99ca879e7 Mark some public and to-be-public classes as `@final`
This indicates at least for people using type checkers that these
classes are not designed for inheritance and we make no stability
guarantees regarding inheritance of them.

Currently this doesn't show up in the docs. Sphinx does actually support
`@final`, however it only works when imported directly from `typing`,
while we import from `_pytest.compat`.

In the future there might also be a `@sealed` decorator which would
cover some more cases.
2020-09-22 12:40:40 +03:00
Florian Bruhin 89305e7b09
Improve output for missing config keys (#7572)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-09-19 12:57:29 -03:00
Bruno Oliveira 9bfd14a443
Merge pull request #7749 from bluetech/fix-get_source-crash 2020-09-19 10:38:32 -03:00
Sorin Sbarnea da21fc5883
Improve output for missing required plugins/unknown config keys (#7723)
Co-authored-by: Florian Bruhin <me@the-compiler.org>
2020-09-16 12:13:17 +02:00
Ran Benita d18cb961cf assertion/rewrite: fix internal error on collection error due to decorated function
For decorated functions, the lineno of the FunctionDef AST node points
to the `def` line, not to the first decorator line. On the other hand,
in code objects, the `co_firstlineno` points to the first decorator
line.

Assertion rewriting inserts some imports to code it rewrites. The
imports are inserted at the lineno of the first statement in the AST. In
turn, the code object compiled from the rewritten AST uses the lineno of
the first statement (which is the first inserted import).

This means that given a module like this,

```py
@foo
@bar
def baz(): pass
```

the lineno of the code object without assertion rewriting
(`--assertion=plain`) is 1, but with assertion rewriting it is 3.

And *this* causes some issues for the exception repr when e.g. the
decorator line is invalid and raises during collection. The code becomes
confused and crashes with

INTERNALERROR>   File "_pytest/_code/code.py", line 638, in get_source
INTERNALERROR>     lines.append(space_prefix + source.lines[line_index].strip())
INTERNALERROR> IndexError: list index out of range

Fix it by special casing decorators. Maybe there are other cases like
this but off hand I can't think of another Python construct where the
lineno of the item would be after its first line, and this is the only
such issue we have had reported.
2020-09-12 23:05:08 +03:00
Bruno Oliveira 634cde9506
Merge pull request #7745 from asottile/exec_globals_type_problem
Fix INTERNALERROR when accessing locals / globals with faulty `exec`
2020-09-12 08:09:48 -03:00
Bruno Oliveira ec58ae5bae
Merge pull request #7736 from nicoddemus/extend-fixture-parametrize-1953 2020-09-12 08:08:31 -03:00
Anthony Sottile 96a17b1683 Fix INTERNALERROR when accessing locals / globals with faulty `exec` 2020-09-11 18:13:48 -07:00
Ran Benita e0dd2111a0 Merge pull request #7720 from pytest-dev/release-6.0.2
Prepare release 6.0.2

(cherry picked from commit fe69bd5baf6b8d1713e16caffc7a5e8dab63bc0f)
2020-09-12 02:05:47 +03:00
Bruno Oliveira c00fe960ba Allow ovewriting a parametrized fixture while reusing the parent fixture's value
Fix #1953
2020-09-11 16:53:34 -03:00
Sorin Sbarnea 1df2471f17
Make min duration configurable for slowest tests (#7667)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-09-05 09:18:29 -03:00
Ran Benita 885d969484
Merge pull request #7685 from bluetech/py-to-pathlib-2
config: start migrating Config.{rootdir,inifile} from py.path.local to pathlib
2020-09-04 18:42:52 +03:00
Bruno Oliveira 0d0b798663
Merge pull request #7708 from nicoddemus/repr-line-7707
Fix handle of exceptions in ReprEntry with tb=line
2020-09-04 12:06:11 -03:00
Ran Benita a346028006 config: add Config.{rootpath,inipath}, turn Config.{rootdir,inifile} to properties 2020-09-04 18:04:25 +03:00
Bruno Oliveira 19e99ab413
Integrate warnings filtering directly into Config (#7700)
Warnings are a central part of Python, so much that Python itself has
command-line and environtment variables to handle warnings.

By moving the concept of warning handling into Config, it becomes natural to
filter warnings issued as early as possible, even before the "_pytest.warnings"
plugin is given a chance to spring into action. This also avoids the weird
coupling between config and the warnings plugin that was required before.

Fix #6681
Fix #2891
Fix #7620
Fix #7626
Close #7649

Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-09-04 11:57:15 -03:00
Bruno Oliveira 9f672c85c5 Fix handle of exceptions in ReprEntry with tb=line
Fix #7707
2020-09-03 07:44:45 -03:00
Ran Benita 98891a5947 python: skip pytest_pycollect_makeitem work on certain names
When a Python object (module/class/instance) is collected, for each name
in `obj.__dict__` (and up its MRO) the pytest_pycollect_makeitem hook is
called for potentially creating a node for it.

These Python objects have a bunch of builtin attributes that are
extremely unlikely to be collected. But due to their pervasiveness,
dispatching the hook for them ends up being mildly expensive and also
pollutes PYTEST_DEBUG=1 output and such.

Let's just ignore these attributes.

On the pandas test suite commit 04e9e0afd476b1b8bed930e47bf60e,
collect only, irrelevant lines snipped, about 5% improvement:

Before:

```
         51195095 function calls (48844352 primitive calls) in 39.089 seconds

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
226602/54    0.145    0.000   38.940    0.721 manager.py:90(_hookexec)
    72227    0.285    0.000   20.146    0.000 python.py:424(_makeitem)
    72227    0.171    0.000   16.678    0.000 python.py:218(pytest_pycollect_makeitem)
```

After:

```
          48410921 function calls (46240870 primitive calls) in 36.950 seconds

    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 181429/54    0.113    0.000   36.777    0.681 manager.py:90(_hookexec)
     27054    0.130    0.000   17.755    0.001 python.py:465(_makeitem)
     27054    0.121    0.000   16.219    0.001 python.py:218(pytest_pycollect_makeitem)
```
2020-08-26 17:43:57 +03:00
Ran Benita a267a622eb python: fix empty parametrize() leading to "NotSetType.token" id
In ff8b7884e8 NOTSET was changed to a
singleton enum, which ended up unexpectedly triggering a code path in ID
generation which checks for `isinstance(Enum)`.

Add an explicit case for it, which is not too bad anyway.
2020-08-25 22:01:43 +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 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
Bruno Oliveira ef946d557c Remove resultlog plugin 2020-08-19 08:14:28 -03:00
Bruno Oliveira b32c48ee05 Add bottom changelog deprecation notice 2020-08-19 08:14:28 -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 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
Ran Benita 8056a677b4 Add changelog for PR #7631 2020-08-14 11:02:44 +03:00
Bruno Oliveira 36c8bb492e get_dirs_from_args handles paths with invalid syntax
Fix #7638
2020-08-12 17:20:09 -03:00
Maximilian Cosmo Sitter 15d8293241
Remove faq.rst from docs (#7635) 2020-08-12 14:47:34 -03:00
Bruno Oliveira 07f7372aff
Merge pull request #7586 from nicoddemus/cp-release
Merge pull request #7584 from pytest-dev/release-6.0.1
2020-08-01 11:00:38 -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 e49f1d6f60 Merge pull request #7584 from pytest-dev/release-6.0.1
Prepare release 6.0.1

(cherry picked from commit 022bff27a71406bd5dc4794d34f1fbbf56a45250)
2020-07-30 09:46:53 -03:00
Ran Benita 924e466c98 Add missing changelog for issue 7569 2020-07-30 12:38:40 +03:00
Bruno Oliveira e691d3ee52 Merge remote-tracking branch 'upstream/6.0.x' into fix-changelog-entries-release-process 2020-07-29 11:27:08 -03:00
Bruno Oliveira fe252848c5 Merge pull request #7561 from nicoddemus/longreprtext-7559 2020-07-29 09:47:31 -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 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 edb6211e36 Merge pull request #7565 from bluetech/pylint-callable-2
mark: fix pylint not-callable error on pytest.mark.parametrize(...), again
(cherry picked from commit f9837f953c)
2020-07-29 11:51:08 +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
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
pytest bot 1e4b8d447c Prepare release version 6.0.0 2020-07-28 11:44:27 +00: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
Kelton Bassingthwaite dbc50a7061
Clarify usage of usefixtures mark in hooks
Fix #7512

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
2020-07-21 23:00:47 -03:00
Anthony Sottile 8616a5f1d9 Preserve newlines when captured with capfd 2020-07-20 10:31:20 -07:00
Debi Mishra 25b56e9c69 docs: Add a note about -q option used in getting started guide 2020-07-20 01:28:11 +05:30
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
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
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 1667d138aa Use sphinx references for NO_COLOR and FORCE_COLOR in changelog 2020-07-10 09:30:04 -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 7934ac280f Add changelog entry for Frame removals 2020-07-10 13:08:56 +03:00
Bruno Oliveira 0a0c14dfac
Merge pull request #7459 from nicoddemus/release-6.0.0rc1 2020-07-09 21:25:58 -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
Bruno Oliveira 7d033a8950 Prepare release version 6.0.0rc1 2020-07-08 17:51:01 -04: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
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 40301effb8 Add changelog entry for code/source changes 2020-07-04 11:45:28 +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
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
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
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
Gleb Nikonorov ac89d6532a replace stderr warnings with the warnings module 2020-06-20 12:15:58 -04:00
Ram Rachum dd446bee5e Fix exception causes all over the codebase 2020-06-19 22:02:24 +03:00
Bruno Oliveira 88a187aae8
Merge pull request #7382 from gnikonorov/fix_issue_4049_changelog_title
fix changelog file name for issue 4049 fix
2020-06-16 22:10:40 -03:00
Gleb Nikonorov ab19148c2a fix changelog file name for issue 4049 fix 2020-06-16 20:59:58 -04:00
Andrew a67c553beb
Disable caching when evaluating expressions in marks (#7373) 2020-06-16 12:39:36 +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 c27550731d Require py>=1.8.2 so we can rely on correct hash() of py.path.local on Windows
See https://github.com/pytest-dev/py/blob/1.8.2/CHANGELOG#L4.
Fixes #7357.
2020-06-15 19:36:38 +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
Bruno Oliveira 3151219785 assertoutcomes() only accepts plural forms
Fix #6505
2020-06-13 10:29:22 -03:00
Bruno Oliveira aaa6f1c3fa
Merge pull request #7330 from gnikonorov/issue_7305 2020-06-12 19:35:38 -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
Bruno Oliveira ab331c906e Suppress errors while removing tmpdir's lock files
Fix #5456
2020-06-11 18:59:51 -03:00
Gleb Nikonorov 57415e68ee
Update changelog/7305.feature.rst
Co-authored-by: Ran Benita <ran@unusedvar.com>
2020-06-11 16:55:25 -04:00
Florian Bruhin e36d5c05c6 doc: Explain indirect parametrization and markers for fixtures 2020-06-10 14:27:45 +02:00
Gleb Nikonorov 95cb7fb676 review feedback 2020-06-10 00:44:22 -04:00
Bruno Oliveira 10cee92955 Fix typo 2020-06-09 14:58:57 -03:00
Bruno Oliveira 5a78df4bd0 Update CHANGELOG 2020-06-09 14:43:04 -03:00
ibriquem e2e7f15b71 Make dataclasses/attrs comparison recursive, fixes #4675 2020-06-09 14:39:40 -03:00
piotrhm e862643b3f Update 1120.bugfix.rst 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 d5a8bf7c6c Improve CHANGELOG 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 13add4df43 documentation fixes 2020-06-07 15:37:50 -04:00
Gleb Nikonorov 42deba59e7 Update documentation as suggested 2020-06-06 22:34:15 -04:00
Gleb Nikonorov f760b105ef Touchup pre-PR 2020-06-06 11:06:08 -04: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 da5851c13e
Update changelog/7291.trivial.rst 2020-06-02 11:01:37 -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
Gleb Nikonorov a5d13d4ced Add changelog entry 2020-06-02 08:21:57 -04: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
Gleb Nikonorov 9ae94b08e2 Add documentation 2020-05-31 11:58:39 -04: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
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
Maximilian Cosmo Sitter b32f4de891
Issue 7202 - Point development guide to contributing section (#7280) 2020-05-31 09:37:26 +03:00
Bruno Oliveira b98aa195e0 Add test and changelog for #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
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
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 6546d1f725
Prevent pytest from printing ConftestImportFailure traceback 2020-05-25 13:57:03 +02:00
Anthony Sottile c594bbbd19
Merge pull request #7240 from DahlitzFlorian/fix-issue-7233
Add note about --strict and --strict-markers to references
2020-05-23 12:31:27 -07: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
Claire Cecil 79701c65ed
Added support for less verbose version information (#7169) 2020-05-23 11:27:58 -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 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