Compare commits
110 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9a96cdee8 | ||
|
|
19a15a94ee | ||
|
|
4e0f99260d | ||
|
|
176c7771fb | ||
|
|
e856638ba0 | ||
|
|
dd9a27cf54 | ||
|
|
d4e4ab5b3d | ||
|
|
e2a0987156 | ||
|
|
bd68c2a3dc | ||
|
|
5e8c47faad | ||
|
|
48ec7d28c6 | ||
|
|
350c27c8b4 | ||
|
|
92d6a0500b | ||
|
|
6f2c0fd2e8 | ||
|
|
55a58bcd3d | ||
|
|
0b40749c98 | ||
|
|
adccb63de0 | ||
|
|
41604eeb3e | ||
|
|
85288b5321 | ||
|
|
5f9db8a017 | ||
|
|
957adbbbc7 | ||
|
|
990d75b7e6 | ||
|
|
f9e3a5395c | ||
|
|
0760406480 | ||
|
|
14580c7e31 | ||
|
|
35800a2f73 | ||
|
|
abc890079f | ||
|
|
dc5a4fbe23 | ||
|
|
285524c6cd | ||
|
|
cefe6bfec3 | ||
|
|
ac633b8969 | ||
|
|
0b8c35516f | ||
|
|
96de232791 | ||
|
|
2fc1f7b8dc | ||
|
|
dae238c9b1 | ||
|
|
b27ba97721 | ||
|
|
2b56c7e1ce | ||
|
|
2bee7d7c3e | ||
|
|
713b9e54c3 | ||
|
|
ba4b8c869c | ||
|
|
82e9013e73 | ||
|
|
5cefcb2052 | ||
|
|
b94eb4cb7b | ||
|
|
9275012ef7 | ||
|
|
14142b9113 | ||
|
|
0123b29ed7 | ||
|
|
16efa1bfef | ||
|
|
5624e366c1 | ||
|
|
b88f5df4ce | ||
|
|
3a402811de | ||
|
|
e05b33ed16 | ||
|
|
2e11ea6108 | ||
|
|
18786992bb | ||
|
|
3173a26388 | ||
|
|
5e7b8d813b | ||
|
|
afac1f0021 | ||
|
|
0783030357 | ||
|
|
d910175b9f | ||
|
|
6b2bae9392 | ||
|
|
7ef44913a1 | ||
|
|
813ef9e88f | ||
|
|
f2dd9cc63e | ||
|
|
ce8b1dfa04 | ||
|
|
a73d0151a6 | ||
|
|
3cb1457e6d | ||
|
|
90dfee5da5 | ||
|
|
77a995ffad | ||
|
|
810db2726d | ||
|
|
0383d43645 | ||
|
|
76c2a8ebbe | ||
|
|
71a7fd02a5 | ||
|
|
7bc8cb8e2b | ||
|
|
dee8d94876 | ||
|
|
a20880cca2 | ||
|
|
ae9465215e | ||
|
|
1555973487 | ||
|
|
3322c1e033 | ||
|
|
7678f891f9 | ||
|
|
4f2abd7ae0 | ||
|
|
122cf60b27 | ||
|
|
63e3d89647 | ||
|
|
122748a6cf | ||
|
|
1f639e2c22 | ||
|
|
83ba5eb58a | ||
|
|
d07c5ba4ae | ||
|
|
b162ab6a45 | ||
|
|
57141dc708 | ||
|
|
bad4ffc3a7 | ||
|
|
71ad5b0fbb | ||
|
|
3fada8c8ee | ||
|
|
271dc7f17a | ||
|
|
19eb0590f1 | ||
|
|
eaa05531ed | ||
|
|
74aed6ea4c | ||
|
|
cfa9ebc91f | ||
|
|
b0fd8742da | ||
|
|
12cc729f6b | ||
|
|
1c5efffd90 | ||
|
|
8c9ea5e055 | ||
|
|
c58b0fb4ac | ||
|
|
4011af68cd | ||
|
|
9637b3e376 | ||
|
|
33c3ec66b7 | ||
|
|
a79acf279a | ||
|
|
9a4c0b991b | ||
|
|
b490f5f979 | ||
|
|
acfd0fd9d6 | ||
|
|
88434f1f42 | ||
|
|
4d01740be3 | ||
|
|
07792c7113 |
7
.github/PULL_REQUEST_TEMPLATE.md
vendored
7
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -2,15 +2,14 @@
|
||||
Thanks for submitting a PR, your contribution is really appreciated!
|
||||
|
||||
Here is a quick checklist that should be present in PRs.
|
||||
(please delete this text from the final description, this is just a guideline)
|
||||
-->
|
||||
|
||||
- [ ] Target the `master` branch for bug fixes, documentation updates and trivial changes.
|
||||
- [ ] Target the `features` branch for new features, improvements, and removals/deprecations.
|
||||
- [ ] Include documentation when adding new features.
|
||||
- [ ] Include new tests or update existing tests when applicable.
|
||||
|
||||
Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:
|
||||
Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:
|
||||
|
||||
- [ ] Create a new changelog file in the `changelog` folder, with a name like `<ISSUE NUMBER>.<TYPE>.rst`. See [changelog/README.rst](https://github.com/pytest-dev/pytest/blob/master/changelog/README.rst) for details.
|
||||
- [ ] Add yourself to `AUTHORS` in alphabetical order;
|
||||
- [ ] Add yourself to `AUTHORS` in alphabetical order.
|
||||
-->
|
||||
|
||||
17
.travis.yml
17
.travis.yml
@@ -35,7 +35,9 @@ jobs:
|
||||
- test $(python -c 'import sys; print("%d%d" % sys.version_info[0:2])') = 37
|
||||
|
||||
# Full run of latest supported version, without xdist.
|
||||
- env: TOXENV=py37
|
||||
# Coverage for:
|
||||
# - test_sys_breakpoint_interception (via pexpect).
|
||||
- env: TOXENV=py37-pexpect PYTEST_COVERAGE=1
|
||||
python: '3.7'
|
||||
|
||||
# Coverage tracking is slow with pypy, skip it.
|
||||
@@ -49,18 +51,16 @@ jobs:
|
||||
# - pytester's LsofFdLeakChecker
|
||||
# - TestArgComplete (linux only)
|
||||
# - numpy
|
||||
# - old attrs
|
||||
# Empty PYTEST_ADDOPTS to run this non-verbose.
|
||||
- env: TOXENV=py37-lsof-numpy-twisted-xdist PYTEST_COVERAGE=1 PYTEST_ADDOPTS=
|
||||
- env: TOXENV=py37-lsof-oldattrs-numpy-twisted-xdist PYTEST_COVERAGE=1 PYTEST_ADDOPTS=
|
||||
|
||||
# Specialized factors for py37.
|
||||
# Coverage for:
|
||||
# - test_sys_breakpoint_interception (via pexpect).
|
||||
- env: TOXENV=py37-pexpect PYTEST_COVERAGE=1
|
||||
- env: TOXENV=py37-pluggymaster-xdist
|
||||
- env: TOXENV=py37-freeze
|
||||
|
||||
- env: TOXENV=py38-xdist
|
||||
python: '3.8-dev'
|
||||
python: '3.8'
|
||||
|
||||
- stage: baseline
|
||||
env: TOXENV=py36-xdist
|
||||
@@ -94,11 +94,6 @@ jobs:
|
||||
tags: true
|
||||
repo: pytest-dev/pytest
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- python: '3.8-dev'
|
||||
env: TOXENV=py38-xdist
|
||||
|
||||
before_script:
|
||||
- |
|
||||
# Do not (re-)upload coverage with cron runs.
|
||||
|
||||
2
AUTHORS
2
AUTHORS
@@ -70,6 +70,7 @@ Daniel Hahler
|
||||
Daniel Nuri
|
||||
Daniel Wandschneider
|
||||
Danielle Jenkins
|
||||
Daniil Galiev
|
||||
Dave Hunt
|
||||
David Díaz-Barquero
|
||||
David Mohr
|
||||
@@ -267,5 +268,6 @@ Wouter van Ackooy
|
||||
Xixi Zhao
|
||||
Xuan Luong
|
||||
Xuecong Liao
|
||||
Yoav Caspi
|
||||
Zac Hatfield-Dodds
|
||||
Zoltán Máté
|
||||
|
||||
@@ -13,11 +13,68 @@ with advance notice in the **Deprecations** section of releases.
|
||||
file is managed by towncrier. You *may* edit previous change logs to
|
||||
fix problems like typo corrections or such.
|
||||
To add a new change log entry, please see
|
||||
https://pip.pypa.io/en/latest/development/#adding-a-news-entry
|
||||
https://pip.pypa.io/en/latest/development/contributing/#news-entries
|
||||
we named the news folder changelog
|
||||
|
||||
.. towncrier release notes start
|
||||
|
||||
pytest 5.2.4 (2019-11-15)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- `#6194 <https://github.com/pytest-dev/pytest/issues/6194>`_: Fix incorrect discovery of non-test ``__init__.py`` files.
|
||||
|
||||
|
||||
- `#6197 <https://github.com/pytest-dev/pytest/issues/6197>`_: Revert "The first test in a package (``__init__.py``) marked with ``@pytest.mark.skip`` is now correctly skipped.".
|
||||
|
||||
|
||||
pytest 5.2.3 (2019-11-14)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- `#5830 <https://github.com/pytest-dev/pytest/issues/5830>`_: The first test in a package (``__init__.py``) marked with ``@pytest.mark.skip`` is now correctly skipped.
|
||||
|
||||
|
||||
- `#6099 <https://github.com/pytest-dev/pytest/issues/6099>`_: Fix ``--trace`` when used with parametrized functions.
|
||||
|
||||
|
||||
- `#6183 <https://github.com/pytest-dev/pytest/issues/6183>`_: Using ``request`` as a parameter name in ``@pytest.mark.parametrize`` now produces a more
|
||||
user-friendly error.
|
||||
|
||||
|
||||
pytest 5.2.2 (2019-10-24)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- `#5206 <https://github.com/pytest-dev/pytest/issues/5206>`_: Fix ``--nf`` to not forget about known nodeids with partial test selection.
|
||||
|
||||
|
||||
- `#5906 <https://github.com/pytest-dev/pytest/issues/5906>`_: Fix crash with ``KeyboardInterrupt`` during ``--setup-show``.
|
||||
|
||||
|
||||
- `#5946 <https://github.com/pytest-dev/pytest/issues/5946>`_: Fixed issue when parametrizing fixtures with numpy arrays (and possibly other sequence-like types).
|
||||
|
||||
|
||||
- `#6044 <https://github.com/pytest-dev/pytest/issues/6044>`_: Properly ignore ``FileNotFoundError`` exceptions when trying to remove old temporary directories,
|
||||
for instance when multiple processes try to remove the same directory (common with ``pytest-xdist``
|
||||
for example).
|
||||
|
||||
|
||||
pytest 5.2.1 (2019-10-06)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- `#5902 <https://github.com/pytest-dev/pytest/issues/5902>`_: Fix warnings about deprecated ``cmp`` attribute in ``attrs>=19.2``.
|
||||
|
||||
|
||||
pytest 5.2.0 (2019-09-28)
|
||||
=========================
|
||||
|
||||
@@ -34,7 +91,7 @@ Features
|
||||
|
||||
- `#1682 <https://github.com/pytest-dev/pytest/issues/1682>`_: The ``scope`` parameter of ``@pytest.fixture`` can now be a callable that receives
|
||||
the fixture name and the ``config`` object as keyword-only parameters.
|
||||
See `the docs <https://docs.pytest.org/en/fixture.html#dynamic-scope>`__ for more information.
|
||||
See `the docs <https://docs.pytest.org/en/latest/fixture.html#dynamic-scope>`__ for more information.
|
||||
|
||||
|
||||
- `#5764 <https://github.com/pytest-dev/pytest/issues/5764>`_: New behavior of the ``--pastebin`` option: failures to connect to the pastebin server are reported, without failing the pytest run
|
||||
@@ -205,9 +262,6 @@ Bug Fixes
|
||||
- `#5477 <https://github.com/pytest-dev/pytest/issues/5477>`_: The XML file produced by ``--junitxml`` now correctly contain a ``<testsuites>`` root element.
|
||||
|
||||
|
||||
- `#5523 <https://github.com/pytest-dev/pytest/issues/5523>`_: Fixed using multiple short options together in the command-line (for example ``-vs``) in Python 3.8+.
|
||||
|
||||
|
||||
- `#5524 <https://github.com/pytest-dev/pytest/issues/5524>`_: Fix issue where ``tmp_path`` and ``tmpdir`` would not remove directories containing files marked as read-only,
|
||||
which could lead to pytest crashing when executed a second time with the ``--basetemp`` option.
|
||||
|
||||
@@ -491,6 +545,32 @@ Improved Documentation
|
||||
- `#5416 <https://github.com/pytest-dev/pytest/issues/5416>`_: Fix PytestUnknownMarkWarning in run/skip example.
|
||||
|
||||
|
||||
pytest 4.6.6 (2019-10-11)
|
||||
=========================
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
- `#5523 <https://github.com/pytest-dev/pytest/issues/5523>`_: Fixed using multiple short options together in the command-line (for example ``-vs``) in Python 3.8+.
|
||||
|
||||
|
||||
- `#5537 <https://github.com/pytest-dev/pytest/issues/5537>`_: Replace ``importlib_metadata`` backport with ``importlib.metadata`` from the
|
||||
standard library on Python 3.8+.
|
||||
|
||||
|
||||
- `#5806 <https://github.com/pytest-dev/pytest/issues/5806>`_: Fix "lexer" being used when uploading to bpaste.net from ``--pastebin`` to "text".
|
||||
|
||||
|
||||
- `#5902 <https://github.com/pytest-dev/pytest/issues/5902>`_: Fix warnings about deprecated ``cmp`` attribute in ``attrs>=19.2``.
|
||||
|
||||
|
||||
|
||||
Trivial/Internal Changes
|
||||
------------------------
|
||||
|
||||
- `#5801 <https://github.com/pytest-dev/pytest/issues/5801>`_: Fixes python version checks (detected by ``flake8-2020``) in case python4 becomes a thing.
|
||||
|
||||
|
||||
pytest 4.6.5 (2019-08-05)
|
||||
=========================
|
||||
|
||||
|
||||
22
README.rst
22
README.rst
@@ -111,14 +111,28 @@ Consult the `Changelog <https://docs.pytest.org/en/latest/changelog.html>`__ pag
|
||||
Support pytest
|
||||
--------------
|
||||
|
||||
You can support pytest by obtaining a `Tidelift subscription`_.
|
||||
`Open Collective`_ is an online funding platform for open and transparent communities.
|
||||
It provide tools to raise money and share your finances in full transparency.
|
||||
|
||||
Tidelift gives software development teams a single source for purchasing and maintaining their software,
|
||||
with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.
|
||||
It is the platform of choice for individuals and companies that want to make one-time or
|
||||
monthly donations directly to the project.
|
||||
|
||||
See more datails in the `pytest collective`_.
|
||||
|
||||
.. _Open Collective: https://opencollective.com
|
||||
.. _pytest collective: https://opencollective.com/pytest
|
||||
|
||||
|
||||
.. _`Tidelift subscription`: https://tidelift.com/subscription/pkg/pypi-pytest?utm_source=pypi-pytest&utm_medium=referral&utm_campaign=readme
|
||||
pytest for enterprise
|
||||
---------------------
|
||||
|
||||
Available as part of the Tidelift Subscription.
|
||||
|
||||
The maintainers of pytest and thousands of other packages are working with Tidelift to deliver commercial support and
|
||||
maintenance for the open source dependencies you use to build your applications.
|
||||
Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use.
|
||||
|
||||
`Learn more. <https://tidelift.com/subscription/pkg/pypi-pytest?utm_source=pypi-pytest&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_
|
||||
|
||||
Security
|
||||
^^^^^^^^
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<li><a href="{{ pathto('backwards-compatibility') }}">Backwards Compatibility</a></li>
|
||||
<li><a href="{{ pathto('py27-py34-deprecation') }}">Python 2.7 and 3.4 Support</a></li>
|
||||
<li><a href="{{ pathto('sponsor') }}">Sponsor</a></li>
|
||||
<li><a href="{{ pathto('tidelift') }}">pytest for Enterprise</a></li>
|
||||
<li><a href="{{ pathto('license') }}">License</a></li>
|
||||
<li><a href="{{ pathto('contact') }}">Contact Channels</a></li>
|
||||
</ul>
|
||||
|
||||
@@ -6,6 +6,10 @@ Release announcements
|
||||
:maxdepth: 2
|
||||
|
||||
|
||||
release-5.2.4
|
||||
release-5.2.3
|
||||
release-5.2.2
|
||||
release-5.2.1
|
||||
release-5.2.0
|
||||
release-5.1.3
|
||||
release-5.1.2
|
||||
|
||||
@@ -29,7 +29,6 @@ Thanks to all who contributed to this release, among them:
|
||||
* Michael Goerz
|
||||
* Ran Benita
|
||||
* Tomáš Chvátal
|
||||
* aklajnert
|
||||
|
||||
|
||||
Happy testing,
|
||||
|
||||
23
doc/en/announce/release-5.2.1.rst
Normal file
23
doc/en/announce/release-5.2.1.rst
Normal file
@@ -0,0 +1,23 @@
|
||||
pytest-5.2.1
|
||||
=======================================
|
||||
|
||||
pytest 5.2.1 has just been released to PyPI.
|
||||
|
||||
This is a bug-fix release, being a drop-in replacement. To upgrade::
|
||||
|
||||
pip install --upgrade pytest
|
||||
|
||||
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
|
||||
|
||||
Thanks to all who contributed to this release, among them:
|
||||
|
||||
* Anthony Sottile
|
||||
* Bruno Oliveira
|
||||
* Florian Bruhin
|
||||
* Hynek Schlawack
|
||||
* Kevin J. Foley
|
||||
* tadashigaki
|
||||
|
||||
|
||||
Happy testing,
|
||||
The pytest Development Team
|
||||
29
doc/en/announce/release-5.2.2.rst
Normal file
29
doc/en/announce/release-5.2.2.rst
Normal file
@@ -0,0 +1,29 @@
|
||||
pytest-5.2.2
|
||||
=======================================
|
||||
|
||||
pytest 5.2.2 has just been released to PyPI.
|
||||
|
||||
This is a bug-fix release, being a drop-in replacement. To upgrade::
|
||||
|
||||
pip install --upgrade pytest
|
||||
|
||||
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
|
||||
|
||||
Thanks to all who contributed to this release, among them:
|
||||
|
||||
* Albert Tugushev
|
||||
* Andrzej Klajnert
|
||||
* Anthony Sottile
|
||||
* Bruno Oliveira
|
||||
* Daniel Hahler
|
||||
* Florian Bruhin
|
||||
* Nattaphoom Chaipreecha
|
||||
* Oliver Bestwalter
|
||||
* Philipp Loose
|
||||
* Ran Benita
|
||||
* Victor Maryama
|
||||
* Yoav Caspi
|
||||
|
||||
|
||||
Happy testing,
|
||||
The pytest Development Team
|
||||
28
doc/en/announce/release-5.2.3.rst
Normal file
28
doc/en/announce/release-5.2.3.rst
Normal file
@@ -0,0 +1,28 @@
|
||||
pytest-5.2.3
|
||||
=======================================
|
||||
|
||||
pytest 5.2.3 has just been released to PyPI.
|
||||
|
||||
This is a bug-fix release, being a drop-in replacement. To upgrade::
|
||||
|
||||
pip install --upgrade pytest
|
||||
|
||||
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
|
||||
|
||||
Thanks to all who contributed to this release, among them:
|
||||
|
||||
* Anthony Sottile
|
||||
* Brett Cannon
|
||||
* Bruno Oliveira
|
||||
* Daniel Hahler
|
||||
* Daniil Galiev
|
||||
* David Szotten
|
||||
* Florian Bruhin
|
||||
* Patrick Harmon
|
||||
* Ran Benita
|
||||
* Zac Hatfield-Dodds
|
||||
* Zak Hassan
|
||||
|
||||
|
||||
Happy testing,
|
||||
The pytest Development Team
|
||||
22
doc/en/announce/release-5.2.4.rst
Normal file
22
doc/en/announce/release-5.2.4.rst
Normal file
@@ -0,0 +1,22 @@
|
||||
pytest-5.2.4
|
||||
=======================================
|
||||
|
||||
pytest 5.2.4 has just been released to PyPI.
|
||||
|
||||
This is a bug-fix release, being a drop-in replacement. To upgrade::
|
||||
|
||||
pip install --upgrade pytest
|
||||
|
||||
The full changelog is available at https://docs.pytest.org/en/latest/changelog.html.
|
||||
|
||||
Thanks to all who contributed to this release, among them:
|
||||
|
||||
* Anthony Sottile
|
||||
* Bruno Oliveira
|
||||
* Daniel Hahler
|
||||
* Hugo
|
||||
* Michael Shields
|
||||
|
||||
|
||||
Happy testing,
|
||||
The pytest Development Team
|
||||
@@ -104,6 +104,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
|
||||
|
||||
Captured logs are available through the following properties/methods::
|
||||
|
||||
* caplog.messages -> list of format-interpolated log messages
|
||||
* caplog.text -> string containing formatted log output
|
||||
* caplog.records -> list of logging.LogRecord instances
|
||||
* caplog.record_tuples -> list of (logger_name, level, message) tuples
|
||||
|
||||
@@ -277,7 +277,60 @@ You can always peek at the content of the cache using the
|
||||
'test_caching.py::test_function': True,
|
||||
'test_foocompare.py::test_compare': True}
|
||||
cache/nodeids contains:
|
||||
['test_caching.py::test_function']
|
||||
['test_assert1.py::test_function',
|
||||
'test_assert2.py::test_set_comparison',
|
||||
'test_foocompare.py::test_compare',
|
||||
'test_50.py::test_num[0]',
|
||||
'test_50.py::test_num[1]',
|
||||
'test_50.py::test_num[2]',
|
||||
'test_50.py::test_num[3]',
|
||||
'test_50.py::test_num[4]',
|
||||
'test_50.py::test_num[5]',
|
||||
'test_50.py::test_num[6]',
|
||||
'test_50.py::test_num[7]',
|
||||
'test_50.py::test_num[8]',
|
||||
'test_50.py::test_num[9]',
|
||||
'test_50.py::test_num[10]',
|
||||
'test_50.py::test_num[11]',
|
||||
'test_50.py::test_num[12]',
|
||||
'test_50.py::test_num[13]',
|
||||
'test_50.py::test_num[14]',
|
||||
'test_50.py::test_num[15]',
|
||||
'test_50.py::test_num[16]',
|
||||
'test_50.py::test_num[17]',
|
||||
'test_50.py::test_num[18]',
|
||||
'test_50.py::test_num[19]',
|
||||
'test_50.py::test_num[20]',
|
||||
'test_50.py::test_num[21]',
|
||||
'test_50.py::test_num[22]',
|
||||
'test_50.py::test_num[23]',
|
||||
'test_50.py::test_num[24]',
|
||||
'test_50.py::test_num[25]',
|
||||
'test_50.py::test_num[26]',
|
||||
'test_50.py::test_num[27]',
|
||||
'test_50.py::test_num[28]',
|
||||
'test_50.py::test_num[29]',
|
||||
'test_50.py::test_num[30]',
|
||||
'test_50.py::test_num[31]',
|
||||
'test_50.py::test_num[32]',
|
||||
'test_50.py::test_num[33]',
|
||||
'test_50.py::test_num[34]',
|
||||
'test_50.py::test_num[35]',
|
||||
'test_50.py::test_num[36]',
|
||||
'test_50.py::test_num[37]',
|
||||
'test_50.py::test_num[38]',
|
||||
'test_50.py::test_num[39]',
|
||||
'test_50.py::test_num[40]',
|
||||
'test_50.py::test_num[41]',
|
||||
'test_50.py::test_num[42]',
|
||||
'test_50.py::test_num[43]',
|
||||
'test_50.py::test_num[44]',
|
||||
'test_50.py::test_num[45]',
|
||||
'test_50.py::test_num[46]',
|
||||
'test_50.py::test_num[47]',
|
||||
'test_50.py::test_num[48]',
|
||||
'test_50.py::test_num[49]',
|
||||
'test_caching.py::test_function']
|
||||
cache/stepwise contains:
|
||||
[]
|
||||
example/value contains:
|
||||
|
||||
@@ -38,19 +38,24 @@ Full pytest documentation
|
||||
customize
|
||||
example/index
|
||||
bash-completion
|
||||
faq
|
||||
|
||||
backwards-compatibility
|
||||
deprecations
|
||||
py27-py34-deprecation
|
||||
historical-notes
|
||||
license
|
||||
|
||||
contributing
|
||||
development_guide
|
||||
|
||||
sponsor
|
||||
tidelift
|
||||
license
|
||||
contact
|
||||
|
||||
historical-notes
|
||||
talks
|
||||
projects
|
||||
faq
|
||||
contact
|
||||
sponsor
|
||||
|
||||
|
||||
.. only:: html
|
||||
|
||||
|
||||
@@ -134,10 +134,13 @@ progress output, you can write it into a configuration file:
|
||||
.. code-block:: ini
|
||||
|
||||
# content of pytest.ini or tox.ini
|
||||
# setup.cfg files should use [tool:pytest] section instead
|
||||
[pytest]
|
||||
addopts = -ra -q
|
||||
|
||||
# content of setup.cfg
|
||||
[tool:pytest]
|
||||
addopts = -ra -q
|
||||
|
||||
Alternatively, you can set a ``PYTEST_ADDOPTS`` environment variable to add command
|
||||
line options while the environment is in use:
|
||||
|
||||
|
||||
@@ -156,6 +156,8 @@ pytest also introduces new options:
|
||||
a string! This means that it may not be appropriate to enable globally in
|
||||
``doctest_optionflags`` in your configuration file.
|
||||
|
||||
.. versionadded:: 5.1
|
||||
|
||||
|
||||
Continue on failure
|
||||
-------------------
|
||||
|
||||
@@ -475,11 +475,10 @@ Running it results in some skips if we don't have all the python interpreters in
|
||||
.. code-block:: pytest
|
||||
|
||||
. $ pytest -rs -q multipython.py
|
||||
ssssssssssssssssssssssss... [100%]
|
||||
ssssssssssss......sss...... [100%]
|
||||
========================= short test summary info ==========================
|
||||
SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.5' not found
|
||||
SKIPPED [12] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.6' not found
|
||||
3 passed, 24 skipped in 0.12s
|
||||
SKIPPED [15] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.5' not found
|
||||
12 passed, 15 skipped in 0.12s
|
||||
|
||||
Indirect parametrization of optional implementations/imports
|
||||
--------------------------------------------------------------------
|
||||
@@ -678,4 +677,4 @@ Or, if desired, you can ``pip install contextlib2`` and use:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from contextlib2 import ExitStack as does_not_raise
|
||||
from contextlib2 import nullcontext as does_not_raise
|
||||
|
||||
@@ -436,7 +436,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
|
||||
items = [1, 2, 3]
|
||||
print("items is {!r}".format(items))
|
||||
> a, b = items.pop()
|
||||
E TypeError: cannot unpack non-iterable int object
|
||||
E TypeError: 'int' object is not iterable
|
||||
|
||||
failure_demo.py:181: TypeError
|
||||
--------------------------- Captured stdout call ---------------------------
|
||||
@@ -516,7 +516,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
|
||||
def test_z2_type_error(self):
|
||||
items = 3
|
||||
> a, b = items
|
||||
E TypeError: cannot unpack non-iterable int object
|
||||
E TypeError: 'int' object is not iterable
|
||||
|
||||
failure_demo.py:222: TypeError
|
||||
______________________ TestMoreErrors.test_startswith ______________________
|
||||
|
||||
@@ -300,36 +300,33 @@ behave differently if called from a test. But if you
|
||||
absolutely must find out if your application code is
|
||||
running from a test you can do something like this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# content of your_module.py
|
||||
|
||||
|
||||
_called_from_test = False
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# content of conftest.py
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
import sys
|
||||
your_module._called_from_test = True
|
||||
|
||||
sys._called_from_test = True
|
||||
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
import sys
|
||||
|
||||
del sys._called_from_test
|
||||
|
||||
and then check for the ``sys._called_from_test`` flag:
|
||||
and then check for the ``your_module._called_from_test`` flag:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
if hasattr(sys, "_called_from_test"):
|
||||
if your_module._called_from_test:
|
||||
# called from within a test run
|
||||
...
|
||||
else:
|
||||
# called "normally"
|
||||
...
|
||||
|
||||
accordingly in your application. It's also a good idea
|
||||
to use your own application module rather than ``sys``
|
||||
for handling flag.
|
||||
accordingly in your application.
|
||||
|
||||
Adding info to test report header
|
||||
--------------------------------------------------------------
|
||||
|
||||
@@ -301,9 +301,13 @@ are finalized when the last test of a *package* finishes.
|
||||
Use this new feature sparingly and please make sure to report any issues you find.
|
||||
|
||||
|
||||
.. _dynamic scope:
|
||||
|
||||
Dynamic scope
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. versionadded:: 5.2
|
||||
|
||||
In some cases, you might want to change the scope of the fixture without changing the code.
|
||||
To do that, pass a callable to ``scope``. The callable must return a string with a valid scope
|
||||
and will be executed only once - during the fixture definition. It will be called with two
|
||||
|
||||
@@ -28,7 +28,7 @@ Install ``pytest``
|
||||
.. code-block:: bash
|
||||
|
||||
$ pytest --version
|
||||
This is pytest version 5.x.y, imported from $PYTHON_PREFIX/lib/python3.7/site-packages/pytest.py
|
||||
This is pytest version 5.x.y, imported from $PYTHON_PREFIX/lib/python3.6/site-packages/pytest.py
|
||||
|
||||
.. _`simpletest`:
|
||||
|
||||
|
||||
@@ -83,6 +83,39 @@ Changelog
|
||||
|
||||
Consult the :ref:`Changelog <changelog>` page for fixes and enhancements of each version.
|
||||
|
||||
Support pytest
|
||||
--------------
|
||||
|
||||
`Open Collective`_ is an online funding platform for open and transparent communities.
|
||||
It provide tools to raise money and share your finances in full transparency.
|
||||
|
||||
It is the platform of choice for individuals and companies that want to make one-time or
|
||||
monthly donations directly to the project.
|
||||
|
||||
See more datails in the `pytest collective`_.
|
||||
|
||||
.. _Open Collective: https://opencollective.com
|
||||
.. _pytest collective: https://opencollective.com/pytest
|
||||
|
||||
|
||||
pytest for enterprise
|
||||
---------------------
|
||||
|
||||
Available as part of the Tidelift Subscription.
|
||||
|
||||
The maintainers of pytest and thousands of other packages are working with Tidelift to deliver commercial support and
|
||||
maintenance for the open source dependencies you use to build your applications.
|
||||
Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use.
|
||||
|
||||
`Learn more. <https://tidelift.com/subscription/pkg/pypi-pytest?utm_source=pypi-pytest&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_
|
||||
|
||||
Security
|
||||
^^^^^^^^
|
||||
|
||||
pytest has never been associated with a security vunerability, but in any case, to report a
|
||||
security vulnerability please use the `Tidelift security contact <https://tidelift.com/security>`_.
|
||||
Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
@@ -38,7 +38,8 @@ Here are some examples of projects using ``pytest`` (please send notes via :ref:
|
||||
* `execnet <http://codespeak.net/execnet>`_ rapid multi-Python deployment
|
||||
* `pylib <https://pylib.readthedocs.io/en/stable/>`_ cross-platform path, IO, dynamic code library
|
||||
* `bbfreeze <https://pypi.org/project/bbfreeze/>`_ create standalone executables from Python scripts
|
||||
* `pdb++ <http://bitbucket.org/antocuni/pdb>`_ a fancier version of PDB
|
||||
* `pdb++ <https://github.com/pdbpp/pdbpp>`_ a fancier version of PDB
|
||||
* `pudb <https://github.com/inducer/pudb>`_ full-screen console debugger for python
|
||||
* `py-s3fuse <http://code.google.com/p/py-s3fuse/>`_ Amazon S3 FUSE based filesystem
|
||||
* `waskr <http://code.google.com/p/waskr/>`_ WSGI Stats Middleware
|
||||
* `guachi <http://code.google.com/p/guachi/>`_ global persistent configs for Python modules
|
||||
|
||||
@@ -24,3 +24,8 @@ branch will continue to exist so the community itself can contribute patches. Th
|
||||
be happy to accept those patches and make new ``4.6`` releases **until mid-2020**.
|
||||
|
||||
.. _`python_requires`: https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
|
||||
|
||||
Technical Aspects
|
||||
-----------------
|
||||
|
||||
The technical aspects of the Python 2.7 and 3.4 support plan (such as when releases will occurr, how to backport fixes, etc) is described in issue `#5275 <https://github.com/pytest-dev/pytest/issues/5275>`__.
|
||||
|
||||
@@ -59,7 +59,7 @@ pytest.raises
|
||||
|
||||
**Tutorial**: :ref:`assertraises`.
|
||||
|
||||
.. autofunction:: pytest.raises(expected_exception: Exception, [match])
|
||||
.. autofunction:: pytest.raises(expected_exception: Exception [, *, match])
|
||||
:with: excinfo
|
||||
|
||||
pytest.deprecated_call
|
||||
@@ -1003,7 +1003,7 @@ passed multiple times. The expected format is ``name=value``. For example::
|
||||
[pytest]
|
||||
addopts = --maxfail=2 -rf # exit after 2 failures, report fail info
|
||||
|
||||
issuing ``pytest test_hello.py`` actually means::
|
||||
issuing ``pytest test_hello.py`` actually means:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
|
||||
@@ -8,18 +8,6 @@ compensation when possible is welcome to justify time away from friends, family
|
||||
Money is also used to fund local sprints, merchandising (stickers to distribute in conferences for example)
|
||||
and every few years a large sprint involving all members.
|
||||
|
||||
If you or your company benefit from pytest and would like to contribute to the project financially,
|
||||
we are members of two online donation platforms to better suit your needs.
|
||||
|
||||
Tidelift
|
||||
--------
|
||||
|
||||
`Tidelift`_ aims to make Open Source sustainable by offering subscriptions to companies which rely
|
||||
on Open Source packages. This subscription allows it to pay maintainers of those Open Source
|
||||
packages to aid sustainability of the work.
|
||||
|
||||
You can help pytest and the ecosystem by obtaining a `Tidelift subscription`_.
|
||||
|
||||
OpenCollective
|
||||
--------------
|
||||
|
||||
@@ -32,7 +20,6 @@ monthly donations directly to the project.
|
||||
See more datails in the `pytest collective`_.
|
||||
|
||||
|
||||
|
||||
.. _Tidelift: https://tidelift.com
|
||||
.. _Tidelift subscription: https://tidelift.com/subscription/pkg/pypi-pytest
|
||||
.. _Open Collective: https://opencollective.com
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
Talks and Tutorials
|
||||
==========================
|
||||
|
||||
.. sidebar:: Next Open Trainings
|
||||
|
||||
- `3 day hands-on workshop covering pytest, tox and devpi: "Professional Testing with Python" <https://python-academy.com/courses/specialtopics/python_course_testing.html>`_ (English), October 21 - 23, 2019, Leipzig, Germany.
|
||||
|
||||
.. _`funcargs`: funcargs.html
|
||||
|
||||
Books
|
||||
|
||||
45
doc/en/tidelift.rst
Normal file
45
doc/en/tidelift.rst
Normal file
@@ -0,0 +1,45 @@
|
||||
pytest for enterprise
|
||||
=====================
|
||||
|
||||
`Tidelift`_ is working with the maintainers of pytest and thousands of other
|
||||
open source projects to deliver commercial support and maintenance for the open source dependencies you use
|
||||
to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the
|
||||
exact dependencies you use.
|
||||
|
||||
`Get more details <https://tidelift.com/subscription/pkg/pypi-pytest?utm_source=pypi-pytest&utm_medium=referral&utm_campaign=enterprise>`_
|
||||
|
||||
The Tidelift Subscription is a managed open source subscription for application dependencies covering millions of open source projects across JavaScript, Python, Java, PHP, Ruby, .NET, and more.
|
||||
|
||||
Your subscription includes:
|
||||
|
||||
* **Security updates**
|
||||
|
||||
- Tidelift's security response team coordinates patches for new breaking security vulnerabilities and alerts immediately through a private channel, so your software supply chain is always secure.
|
||||
|
||||
* **Licensing verification and indemnification**
|
||||
|
||||
- Tidelift verifies license information to enable easy policy enforcement and adds intellectual property indemnification to cover creators and users in case something goes wrong. You always have a 100% up-to-date bill of materials for your dependencies to share with your legal team, customers, or partners.
|
||||
|
||||
* **Maintenance and code improvement**
|
||||
|
||||
- Tidelift ensures the software you rely on keeps working as long as you need it to work. Your managed dependencies are actively maintained and we recruit additional maintainers where required.
|
||||
|
||||
* **Package selection and version guidance**
|
||||
|
||||
- Tidelift helps you choose the best open source packages from the start—and then guide you through updates to stay on the best releases as new issues arise.
|
||||
|
||||
* **Roadmap input**
|
||||
|
||||
- Take a seat at the table with the creators behind the software you use. Tidelift's participating maintainers earn more income as their software is used by more subscribers, so they're interested in knowing what you need.
|
||||
|
||||
* **Tooling and cloud integration**
|
||||
|
||||
- Tidelift works with GitHub, GitLab, BitBucket, and every cloud platform (and other deployment targets, too).
|
||||
|
||||
The end result? All of the capabilities you expect from commercial-grade software, for the full breadth of open
|
||||
source you use. That means less time grappling with esoteric open source trivia, and more time building your own
|
||||
applications—and your business.
|
||||
|
||||
`Request a demo <https://tidelift.com/subscription/request-a-demo?utm_source=pypi-pytest&utm_medium=referral&utm_campaign=enterprise>`_
|
||||
|
||||
.. _Tidelift: https://tidelift.com
|
||||
@@ -718,6 +718,11 @@ for example ``-x`` if you only want to send one particular failure.
|
||||
|
||||
Currently only pasting to the http://bpaste.net service is implemented.
|
||||
|
||||
.. versionchanged:: 5.2
|
||||
|
||||
If creating the URL fails for any reason, a warning is generated instead of failing the
|
||||
entire test suite.
|
||||
|
||||
Early loading plugins
|
||||
---------------------
|
||||
|
||||
|
||||
@@ -13,5 +13,6 @@ fi
|
||||
python -m coverage combine
|
||||
python -m coverage xml
|
||||
python -m coverage report -m
|
||||
curl -S -L --retry 6 -s https://codecov.io/bash -o codecov-upload.sh
|
||||
# Set --connect-timeout to work around https://github.com/curl/curl/issues/4461
|
||||
curl -S -L --connect-timeout 5 --retry 6 -s https://codecov.io/bash -o codecov-upload.sh
|
||||
bash codecov-upload.sh -Z -X fix -f coverage.xml
|
||||
|
||||
@@ -57,7 +57,7 @@ upload-dir = doc/en/build/html
|
||||
|
||||
[check-manifest]
|
||||
ignore =
|
||||
_pytest/_version.py
|
||||
src/_pytest/_version.py
|
||||
|
||||
[devpi:upload]
|
||||
formats = sdist.tgz,bdist_wheel
|
||||
|
||||
2
setup.py
2
setup.py
@@ -5,7 +5,7 @@ from setuptools import setup
|
||||
INSTALL_REQUIRES = [
|
||||
"py>=1.5.0",
|
||||
"packaging",
|
||||
"attrs>=17.4.0",
|
||||
"attrs>=17.4.0", # should match oldattrs tox env.
|
||||
"more-itertools>=4.0.0",
|
||||
"atomicwrites>=1.0",
|
||||
'pathlib2>=2.2.0;python_version<"3.6"',
|
||||
|
||||
@@ -4,6 +4,7 @@ import sys
|
||||
import traceback
|
||||
from inspect import CO_VARARGS
|
||||
from inspect import CO_VARKEYWORDS
|
||||
from io import StringIO
|
||||
from traceback import format_exception_only
|
||||
from types import CodeType
|
||||
from types import TracebackType
|
||||
@@ -136,7 +137,7 @@ class Frame:
|
||||
def exec_(self, code, **vars):
|
||||
""" exec 'code' in the frame
|
||||
|
||||
'vars' are optiona; additional local variables
|
||||
'vars' are optional; additional local variables
|
||||
"""
|
||||
f_locals = self.f_locals.copy()
|
||||
f_locals.update(vars)
|
||||
@@ -206,7 +207,7 @@ class TracebackEntry:
|
||||
|
||||
@property
|
||||
def locals(self):
|
||||
""" locals of underlaying frame """
|
||||
""" locals of underlying frame """
|
||||
return self.frame.f_locals
|
||||
|
||||
def getfirstlinesource(self):
|
||||
@@ -273,7 +274,7 @@ class TracebackEntry:
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" co_name of underlaying code """
|
||||
""" co_name of underlying code """
|
||||
return self.frame.code.raw.co_name
|
||||
|
||||
|
||||
@@ -301,7 +302,7 @@ class Traceback(list):
|
||||
def cut(self, path=None, lineno=None, firstlineno=None, excludepath=None):
|
||||
""" return a Traceback instance wrapping part of this Traceback
|
||||
|
||||
by provding any combination of path, lineno and firstlineno, the
|
||||
by providing any combination of path, lineno and firstlineno, the
|
||||
first frame to start the to-be-returned traceback is determined
|
||||
|
||||
this allows cutting the first part of a Traceback instance e.g.
|
||||
@@ -865,7 +866,7 @@ class TerminalRepr:
|
||||
def __str__(self):
|
||||
# FYI this is called from pytest-xdist's serialization of exception
|
||||
# information.
|
||||
io = py.io.TextIO()
|
||||
io = StringIO()
|
||||
tw = py.io.TerminalWriter(file=io)
|
||||
self.toterminal(tw)
|
||||
return io.getvalue().strip()
|
||||
@@ -1002,7 +1003,7 @@ class ReprFileLocation(TerminalRepr):
|
||||
|
||||
def toterminal(self, tw):
|
||||
# filename and lineno output for each entry,
|
||||
# using an output format that most editors unterstand
|
||||
# using an output format that most editors understand
|
||||
msg = self.message
|
||||
i = msg.find("\n")
|
||||
if i != -1:
|
||||
|
||||
@@ -8,6 +8,7 @@ from typing import Optional
|
||||
import _pytest._code
|
||||
from _pytest import outcomes
|
||||
from _pytest._io.saferepr import saferepr
|
||||
from _pytest.compat import ATTRS_EQ_FIELD
|
||||
|
||||
# The _reprcompare attribute on the util module is used by the new assertion
|
||||
# interpretation code and assertion rewriter to detect this plugin was
|
||||
@@ -30,7 +31,6 @@ def format_explanation(explanation):
|
||||
for when one explanation needs to span multiple lines, e.g. when
|
||||
displaying diffs.
|
||||
"""
|
||||
explanation = explanation
|
||||
lines = _split_explanation(explanation)
|
||||
result = _format_lines(lines)
|
||||
return "\n".join(result)
|
||||
@@ -375,7 +375,9 @@ def _compare_eq_cls(left, right, verbose, type_fns):
|
||||
fields_to_check = [field for field, info in all_fields.items() if info.compare]
|
||||
elif isattrs(left):
|
||||
all_fields = left.__attrs_attrs__
|
||||
fields_to_check = [field.name for field in all_fields if field.cmp]
|
||||
fields_to_check = [
|
||||
field.name for field in all_fields if getattr(field, ATTRS_EQ_FIELD)
|
||||
]
|
||||
|
||||
same = []
|
||||
diff = []
|
||||
|
||||
@@ -135,7 +135,7 @@ class Cache:
|
||||
readme_path.write_text(README_CONTENT)
|
||||
|
||||
gitignore_path = self._cachedir.joinpath(".gitignore")
|
||||
msg = "# Created by pytest automatically.\n*"
|
||||
msg = "# Created by pytest automatically.\n*\n"
|
||||
gitignore_path.write_text(msg, encoding="UTF-8")
|
||||
|
||||
cachedir_tag_path = self._cachedir.joinpath("CACHEDIR.TAG")
|
||||
@@ -264,8 +264,8 @@ class NFPlugin:
|
||||
self.cached_nodeids = config.cache.get("cache/nodeids", [])
|
||||
|
||||
def pytest_collection_modifyitems(self, session, config, items):
|
||||
new_items = OrderedDict()
|
||||
if self.active:
|
||||
new_items = OrderedDict()
|
||||
other_items = OrderedDict()
|
||||
for item in items:
|
||||
if item.nodeid not in self.cached_nodeids:
|
||||
@@ -276,7 +276,11 @@ class NFPlugin:
|
||||
items[:] = self._get_increasing_order(
|
||||
new_items.values()
|
||||
) + self._get_increasing_order(other_items.values())
|
||||
self.cached_nodeids = [x.nodeid for x in items if isinstance(x, pytest.Item)]
|
||||
else:
|
||||
for item in items:
|
||||
if item.nodeid not in self.cached_nodeids:
|
||||
new_items[item.nodeid] = item
|
||||
self.cached_nodeids.extend(new_items)
|
||||
|
||||
def _get_increasing_order(self, items):
|
||||
return sorted(items, key=lambda item: item.fspath.mtime(), reverse=True)
|
||||
|
||||
@@ -354,3 +354,9 @@ if sys.version_info < (3, 5, 2): # pragma: no cover
|
||||
|
||||
def overload(f): # noqa: F811
|
||||
return f
|
||||
|
||||
|
||||
if getattr(attr, "__version_info__", ()) >= (19, 2):
|
||||
ATTRS_EQ_FIELD = "eq"
|
||||
else:
|
||||
ATTRS_EQ_FIELD = "cmp"
|
||||
|
||||
@@ -195,7 +195,6 @@ def get_plugin_manager():
|
||||
|
||||
|
||||
def _prepareconfig(args=None, plugins=None):
|
||||
warning = None
|
||||
if args is None:
|
||||
args = sys.argv[1:]
|
||||
elif isinstance(args, py.path.local):
|
||||
@@ -213,10 +212,6 @@ def _prepareconfig(args=None, plugins=None):
|
||||
pluginmanager.consider_pluginarg(plugin)
|
||||
else:
|
||||
pluginmanager.register(plugin)
|
||||
if warning:
|
||||
from _pytest.warnings import _issue_warning_captured
|
||||
|
||||
_issue_warning_captured(warning, hook=config.hook, stacklevel=4)
|
||||
return pluginmanager.hook.pytest_cmdline_parse(
|
||||
pluginmanager=pluginmanager, args=args
|
||||
)
|
||||
@@ -663,6 +658,8 @@ class Config:
|
||||
class InvocationParams:
|
||||
"""Holds parameters passed during ``pytest.main()``
|
||||
|
||||
.. versionadded:: 5.1
|
||||
|
||||
.. note::
|
||||
|
||||
Currently the environment variable PYTEST_ADDOPTS is also handled by
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
""" interactive debugging with PDB, the Python Debugger. """
|
||||
import argparse
|
||||
import functools
|
||||
import pdb
|
||||
import sys
|
||||
from doctest import UnexpectedException
|
||||
@@ -274,13 +275,16 @@ class PdbTrace:
|
||||
def _test_pytest_function(pyfuncitem):
|
||||
_pdb = pytestPDB._init_pdb("runcall")
|
||||
testfunction = pyfuncitem.obj
|
||||
pyfuncitem.obj = _pdb.runcall
|
||||
if "func" in pyfuncitem._fixtureinfo.argnames: # pragma: no branch
|
||||
raise ValueError("--trace can't be used with a fixture named func!")
|
||||
pyfuncitem.funcargs["func"] = testfunction
|
||||
new_list = list(pyfuncitem._fixtureinfo.argnames)
|
||||
new_list.append("func")
|
||||
pyfuncitem._fixtureinfo.argnames = tuple(new_list)
|
||||
|
||||
# we can't just return `partial(pdb.runcall, testfunction)` because (on
|
||||
# python < 3.7.4) runcall's first param is `func`, which means we'd get
|
||||
# an exception if one of the kwargs to testfunction was called `func`
|
||||
@functools.wraps(testfunction)
|
||||
def wrapper(*args, **kwargs):
|
||||
func = functools.partial(testfunction, *args, **kwargs)
|
||||
_pdb.runcall(func)
|
||||
|
||||
pyfuncitem.obj = wrapper
|
||||
|
||||
|
||||
def _enter_pdb(node, excinfo, rep):
|
||||
|
||||
@@ -1088,9 +1088,13 @@ def fixture(
|
||||
|
||||
:arg scope: the scope for which this fixture is shared, one of
|
||||
``"function"`` (default), ``"class"``, ``"module"``,
|
||||
``"package"`` or ``"session"``.
|
||||
``"package"`` or ``"session"`` (``"package"`` is considered **experimental**
|
||||
at this time).
|
||||
|
||||
``"package"`` is considered **experimental** at this time.
|
||||
This parameter may also be a callable which receives ``(fixture_name, config)``
|
||||
as parameters, and must return a ``str`` with one of the values mentioned above.
|
||||
|
||||
See :ref:`dynamic scope` in the docs for more information.
|
||||
|
||||
:arg params: an optional list of parameters which will cause multiple
|
||||
invocations of the fixture function and all of the tests
|
||||
@@ -1113,6 +1117,9 @@ def fixture(
|
||||
``fixture_<fixturename>`` and then use
|
||||
``@pytest.fixture(name='<fixturename>')``.
|
||||
"""
|
||||
if params is not None:
|
||||
params = list(params)
|
||||
|
||||
fixture_function, arguments = _parse_fixture_args(
|
||||
callable_or_scope,
|
||||
*args,
|
||||
@@ -1134,8 +1141,6 @@ def fixture(
|
||||
fixture_function
|
||||
)
|
||||
|
||||
if params is not None and not isinstance(params, (list, tuple)):
|
||||
params = list(params)
|
||||
return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name)
|
||||
|
||||
|
||||
|
||||
@@ -488,6 +488,8 @@ def pytest_assertion_pass(item, lineno, orig, expl):
|
||||
"""
|
||||
**(Experimental)**
|
||||
|
||||
.. versionadded:: 5.0
|
||||
|
||||
Hook called whenever an assertion *passes*.
|
||||
|
||||
Use this hook to do some processing after a passing assertion.
|
||||
|
||||
@@ -513,7 +513,7 @@ class LogXML:
|
||||
key = nodeid, slavenode
|
||||
|
||||
if key in self.node_reporters:
|
||||
# TODO: breasks for --dist=each
|
||||
# TODO: breaks for --dist=each
|
||||
return self.node_reporters[key]
|
||||
|
||||
reporter = _NodeReporter(nodeid, self)
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
import logging
|
||||
import re
|
||||
from contextlib import contextmanager
|
||||
|
||||
import py
|
||||
from io import StringIO
|
||||
|
||||
import pytest
|
||||
from _pytest.compat import nullcontext
|
||||
@@ -218,7 +217,7 @@ class LogCaptureHandler(logging.StreamHandler):
|
||||
|
||||
def __init__(self):
|
||||
"""Creates a new log handler."""
|
||||
logging.StreamHandler.__init__(self, py.io.TextIO())
|
||||
logging.StreamHandler.__init__(self, StringIO())
|
||||
self.records = []
|
||||
|
||||
def emit(self, record):
|
||||
@@ -228,7 +227,7 @@ class LogCaptureHandler(logging.StreamHandler):
|
||||
|
||||
def reset(self):
|
||||
self.records = []
|
||||
self.stream = py.io.TextIO()
|
||||
self.stream = StringIO()
|
||||
|
||||
|
||||
class LogCaptureFixture:
|
||||
@@ -356,6 +355,7 @@ def caplog(request):
|
||||
|
||||
Captured logs are available through the following properties/methods::
|
||||
|
||||
* caplog.messages -> list of format-interpolated log messages
|
||||
* caplog.text -> string containing formatted log output
|
||||
* caplog.records -> list of logging.LogRecord instances
|
||||
* caplog.record_tuples -> list of (logger_name, level, message) tuples
|
||||
|
||||
@@ -20,6 +20,8 @@ from _pytest.runner import collect_one_node
|
||||
|
||||
class ExitCode(enum.IntEnum):
|
||||
"""
|
||||
.. versionadded:: 5.0
|
||||
|
||||
Encodes the valid exit codes by pytest.
|
||||
|
||||
Currently users and plugins may supply other exit codes as well.
|
||||
@@ -427,7 +429,7 @@ class Session(nodes.FSCollector):
|
||||
# one or more conftests are not in use at this fspath
|
||||
proxy = FSHookProxy(fspath, pm, remove_mods)
|
||||
else:
|
||||
# all plugis are active for this fspath
|
||||
# all plugins are active for this fspath
|
||||
proxy = self.config.hook
|
||||
return proxy
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class MarkEvaluator:
|
||||
self._mark_name = name
|
||||
|
||||
def __bool__(self):
|
||||
# dont cache here to prevent staleness
|
||||
# don't cache here to prevent staleness
|
||||
return bool(self._get_marks())
|
||||
|
||||
__nonzero__ = __bool__
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
this is a place where we put datastructures used by legacy apis
|
||||
we hope ot remove
|
||||
we hope to remove
|
||||
"""
|
||||
import keyword
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from typing import Set
|
||||
import attr
|
||||
|
||||
from ..compat import ascii_escaped
|
||||
from ..compat import ATTRS_EQ_FIELD
|
||||
from ..compat import getfslineno
|
||||
from ..compat import NOTSET
|
||||
from _pytest.outcomes import fail
|
||||
@@ -367,7 +368,8 @@ class NodeKeywords(MutableMapping):
|
||||
return "<NodeKeywords for node {}>".format(self.node)
|
||||
|
||||
|
||||
@attr.s(cmp=False, hash=False)
|
||||
# mypy cannot find this overload, remove when on attrs>=19.2
|
||||
@attr.s(hash=False, **{ATTRS_EQ_FIELD: False}) # type: ignore
|
||||
class NodeMarkers:
|
||||
"""
|
||||
internal structure for storing marks belonging to a node
|
||||
|
||||
@@ -38,21 +38,35 @@ def ensure_reset_dir(path):
|
||||
path.mkdir()
|
||||
|
||||
|
||||
def on_rm_rf_error(func, path: str, exc, *, start_path):
|
||||
"""Handles known read-only errors during rmtree."""
|
||||
excvalue = exc[1]
|
||||
def on_rm_rf_error(func, path: str, exc, *, start_path) -> bool:
|
||||
"""Handles known read-only errors during rmtree.
|
||||
|
||||
The returned value is used only by our own tests.
|
||||
"""
|
||||
exctype, excvalue = exc[:2]
|
||||
|
||||
# another process removed the file in the middle of the "rm_rf" (xdist for example)
|
||||
# more context: https://github.com/pytest-dev/pytest/issues/5974#issuecomment-543799018
|
||||
if isinstance(excvalue, FileNotFoundError):
|
||||
return False
|
||||
|
||||
if not isinstance(excvalue, PermissionError):
|
||||
warnings.warn(
|
||||
PytestWarning("(rm_rf) error removing {}: {}".format(path, excvalue))
|
||||
PytestWarning(
|
||||
"(rm_rf) error removing {}\n{}: {}".format(path, exctype, excvalue)
|
||||
)
|
||||
)
|
||||
return
|
||||
return False
|
||||
|
||||
if func not in (os.rmdir, os.remove, os.unlink):
|
||||
warnings.warn(
|
||||
PytestWarning("(rm_rf) error removing {}: {}".format(path, excvalue))
|
||||
PytestWarning(
|
||||
"(rm_rf) unknown function {} when removing {}:\n{}: {}".format(
|
||||
path, func, exctype, excvalue
|
||||
)
|
||||
)
|
||||
)
|
||||
return
|
||||
return False
|
||||
|
||||
# Chmod + retry.
|
||||
import stat
|
||||
@@ -73,6 +87,7 @@ def on_rm_rf_error(func, path: str, exc, *, start_path):
|
||||
chmod_rw(str(path))
|
||||
|
||||
func(path)
|
||||
return True
|
||||
|
||||
|
||||
def rm_rf(path: Path):
|
||||
|
||||
@@ -10,6 +10,7 @@ import time
|
||||
import traceback
|
||||
from collections.abc import Sequence
|
||||
from fnmatch import fnmatch
|
||||
from io import StringIO
|
||||
from weakref import WeakKeyDictionary
|
||||
|
||||
import py
|
||||
@@ -351,15 +352,14 @@ class RunResult:
|
||||
|
||||
Attributes:
|
||||
|
||||
:ret: the return value
|
||||
:outlines: list of lines captured from stdout
|
||||
:errlines: list of lines captures from stderr
|
||||
:stdout: :py:class:`LineMatcher` of stdout, use ``stdout.str()`` to
|
||||
:ivar ret: the return value
|
||||
:ivar outlines: list of lines captured from stdout
|
||||
:ivar errlines: list of lines captured from stderr
|
||||
:ivar stdout: :py:class:`LineMatcher` of stdout, use ``stdout.str()`` to
|
||||
reconstruct stdout or the commonly used ``stdout.fnmatch_lines()``
|
||||
method
|
||||
:stderr: :py:class:`LineMatcher` of stderr
|
||||
:duration: duration in seconds
|
||||
|
||||
:ivar stderr: :py:class:`LineMatcher` of stderr
|
||||
:ivar duration: duration in seconds
|
||||
"""
|
||||
|
||||
def __init__(self, ret, outlines, errlines, duration):
|
||||
@@ -454,9 +454,9 @@ class Testdir:
|
||||
|
||||
Attributes:
|
||||
|
||||
:tmpdir: The :py:class:`py.path.local` instance of the temporary directory.
|
||||
:ivar tmpdir: The :py:class:`py.path.local` instance of the temporary directory.
|
||||
|
||||
:plugins: A list of plugins to use with :py:meth:`parseconfig` and
|
||||
:ivar plugins: A list of plugins to use with :py:meth:`parseconfig` and
|
||||
:py:meth:`runpytest`. Initially this is an empty list but plugins can
|
||||
be added to the list. The type of items to add to the list depends on
|
||||
the method using them so refer to them for details.
|
||||
@@ -1219,7 +1219,7 @@ def getdecoded(out):
|
||||
|
||||
class LineComp:
|
||||
def __init__(self):
|
||||
self.stringio = py.io.TextIO()
|
||||
self.stringio = StringIO()
|
||||
|
||||
def assert_contains_lines(self, lines2):
|
||||
"""Assert that lines2 are contained (linearly) in lines1.
|
||||
|
||||
@@ -210,8 +210,8 @@ def pytest_pycollect_makeitem(collector, name, obj):
|
||||
# mock seems to store unbound methods (issue473), normalize it
|
||||
obj = getattr(obj, "__func__", obj)
|
||||
# We need to try and unwrap the function if it's a functools.partial
|
||||
# or a funtools.wrapped.
|
||||
# We musn't if it's been wrapped with mock.patch (python 2 only)
|
||||
# or a functools.wrapped.
|
||||
# We mustn't if it's been wrapped with mock.patch (python 2 only)
|
||||
if not (inspect.isfunction(obj) or inspect.isfunction(get_real_func(obj))):
|
||||
filename, lineno = getfslineno(obj)
|
||||
warnings.warn_explicit(
|
||||
@@ -595,7 +595,7 @@ class Package(Module):
|
||||
# one or more conftests are not in use at this fspath
|
||||
proxy = FSHookProxy(fspath, pm, remove_mods)
|
||||
else:
|
||||
# all plugis are active for this fspath
|
||||
# all plugins are active for this fspath
|
||||
proxy = self.config.hook
|
||||
return proxy
|
||||
|
||||
@@ -965,6 +965,12 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
|
||||
)
|
||||
del argvalues
|
||||
|
||||
if "request" in argnames:
|
||||
fail(
|
||||
"'request' is a reserved name and cannot be used in @pytest.mark.parametrize",
|
||||
pytrace=False,
|
||||
)
|
||||
|
||||
if scope is None:
|
||||
scope = _find_parametrized_scope(argnames, self._arg2fixturedefs, indirect)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from io import StringIO
|
||||
from pprint import pprint
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
@@ -180,7 +181,7 @@ class BaseReport:
|
||||
|
||||
def _report_unserialization_failure(type_name, report_class, reportdict):
|
||||
url = "https://github.com/pytest-dev/pytest/issues"
|
||||
stream = py.io.TextIO()
|
||||
stream = StringIO()
|
||||
pprint("-" * 100, stream=stream)
|
||||
pprint("INTERNALERROR: Unknown entry type returned: %s" % type_name, stream=stream)
|
||||
pprint("report_name: %s" % report_class, stream=stream)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -51,7 +49,6 @@ def _show_fixture_action(fixturedef, msg):
|
||||
capman = config.pluginmanager.getplugin("capturemanager")
|
||||
if capman:
|
||||
capman.suspend_global_capture()
|
||||
out, err = capman.read_global_capture()
|
||||
|
||||
tw = config.get_terminal_writer()
|
||||
tw.line()
|
||||
@@ -74,8 +71,6 @@ def _show_fixture_action(fixturedef, msg):
|
||||
|
||||
if capman:
|
||||
capman.resume_global_capture()
|
||||
sys.stdout.write(out)
|
||||
sys.stderr.write(err)
|
||||
|
||||
|
||||
@pytest.hookimpl(tryfirst=True)
|
||||
|
||||
@@ -122,7 +122,7 @@ def pytest_runtest_makereport(item, call):
|
||||
outcome = yield
|
||||
rep = outcome.get_result()
|
||||
evalxfail = getattr(item, "_evalxfail", None)
|
||||
# unitttest special case, see setting of _unexpectedsuccess
|
||||
# unittest special case, see setting of _unexpectedsuccess
|
||||
if hasattr(item, "_unexpectedsuccess") and rep.when == "call":
|
||||
|
||||
if item._unexpectedsuccess:
|
||||
@@ -132,7 +132,7 @@ def pytest_runtest_makereport(item, call):
|
||||
rep.outcome = "failed"
|
||||
|
||||
elif item.config.option.runxfail:
|
||||
pass # don't interefere
|
||||
pass # don't interfere
|
||||
elif call.excinfo and call.excinfo.errisinstance(xfail.Exception):
|
||||
rep.wasxfail = "reason: " + call.excinfo.value.msg
|
||||
rep.outcome = "skipped"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
This is the script that is actually frozen into an executable: simply executes
|
||||
py.test main().
|
||||
pytest main().
|
||||
"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1148,7 +1148,7 @@ def test_dont_collect_non_function_callable(testdir):
|
||||
"""Test for issue https://github.com/pytest-dev/pytest/issues/331
|
||||
|
||||
In this case an INTERNALERROR occurred trying to report the failure of
|
||||
a test like this one because py test failed to get the source lines.
|
||||
a test like this one because pytest failed to get the source lines.
|
||||
"""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
|
||||
@@ -4187,3 +4187,23 @@ def test_indirect_fixture_does_not_break_scope(testdir):
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=7)
|
||||
|
||||
|
||||
def test_fixture_parametrization_nparray(testdir):
|
||||
pytest.importorskip("numpy")
|
||||
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
from numpy import linspace
|
||||
from pytest import fixture
|
||||
|
||||
@fixture(params=linspace(1, 10, 10))
|
||||
def value(request):
|
||||
return request.param
|
||||
|
||||
def test_bug(value):
|
||||
assert value == value
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.assert_outcomes(passed=10)
|
||||
|
||||
@@ -15,7 +15,7 @@ class TestMetafunc:
|
||||
def Metafunc(self, func, config=None):
|
||||
# the unit tests of this class check if things work correctly
|
||||
# on the funcarg level, so we don't need a full blown
|
||||
# initiliazation
|
||||
# initialization
|
||||
class FixtureInfo:
|
||||
name2fixturedefs = None
|
||||
|
||||
@@ -72,6 +72,19 @@ class TestMetafunc:
|
||||
):
|
||||
metafunc.parametrize("x", [1], scope="doggy")
|
||||
|
||||
def test_parametrize_request_name(self, testdir):
|
||||
"""Show proper error when 'request' is used as a parameter name in parametrize (#6183)"""
|
||||
|
||||
def func(request):
|
||||
raise NotImplementedError()
|
||||
|
||||
metafunc = self.Metafunc(func)
|
||||
with pytest.raises(
|
||||
pytest.fail.Exception,
|
||||
match=r"'request' is a reserved name and cannot be used in @pytest.mark.parametrize",
|
||||
):
|
||||
metafunc.parametrize("request", [1])
|
||||
|
||||
def test_find_parametrized_scope(self):
|
||||
"""unittest for _find_parametrized_scope (#3941)"""
|
||||
from _pytest.python import _find_parametrized_scope
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
from _pytest.main import ExitCode
|
||||
|
||||
|
||||
@pytest.fixture(params=["--setup-only", "--setup-plan", "--setup-show"], scope="module")
|
||||
@@ -267,3 +268,27 @@ def test_show_fixtures_and_execute_test(testdir):
|
||||
result.stdout.fnmatch_lines(
|
||||
["*SETUP F arg*", "*test_arg (fixtures used: arg)F*", "*TEARDOWN F arg*"]
|
||||
)
|
||||
|
||||
|
||||
def test_setup_show_with_KeyboardInterrupt_in_test(testdir):
|
||||
p = testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
def arg():
|
||||
pass
|
||||
def test_arg(arg):
|
||||
raise KeyboardInterrupt()
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--setup-show", p, no_reraise_ctrlc=True)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*SETUP F arg*",
|
||||
"*test_arg (fixtures used: arg)*",
|
||||
"*TEARDOWN F arg*",
|
||||
"*! KeyboardInterrupt !*",
|
||||
"*= no tests ran in *",
|
||||
]
|
||||
)
|
||||
assert result.ret == ExitCode.INTERRUPTED
|
||||
|
||||
@@ -9,6 +9,7 @@ import pytest
|
||||
from _pytest import outcomes
|
||||
from _pytest.assertion import truncate
|
||||
from _pytest.assertion import util
|
||||
from _pytest.compat import ATTRS_EQ_FIELD
|
||||
|
||||
|
||||
def mock_config():
|
||||
@@ -687,7 +688,7 @@ class TestAssert_reprcompare_attrsclass:
|
||||
@attr.s
|
||||
class SimpleDataObject:
|
||||
field_a = attr.ib()
|
||||
field_b = attr.ib(cmp=False)
|
||||
field_b = attr.ib(**{ATTRS_EQ_FIELD: False})
|
||||
|
||||
left = SimpleDataObject(1, "b")
|
||||
right = SimpleDataObject(1, "b")
|
||||
|
||||
@@ -982,8 +982,13 @@ class TestNewFirst:
|
||||
)
|
||||
testdir.tmpdir.join("test_1/test_1.py").setmtime(1)
|
||||
|
||||
result = testdir.runpytest("-v", "--nf")
|
||||
# Running only a subset does not forget about existing ones.
|
||||
result = testdir.runpytest("-v", "--nf", "test_2/test_2.py")
|
||||
result.stdout.fnmatch_lines(
|
||||
["*test_2/test_2.py::test_1[1*", "*test_2/test_2.py::test_1[2*"]
|
||||
)
|
||||
|
||||
result = testdir.runpytest("-v", "--nf")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*test_1/test_1.py::test_1[3*",
|
||||
@@ -1029,7 +1034,7 @@ def test_gitignore(testdir):
|
||||
config = testdir.parseconfig()
|
||||
cache = Cache.for_config(config)
|
||||
cache.set("foo", "bar")
|
||||
msg = "# Created by pytest automatically.\n*"
|
||||
msg = "# Created by pytest automatically.\n*\n"
|
||||
gitignore_path = cache._cachedir.joinpath(".gitignore")
|
||||
assert gitignore_path.read_text(encoding="UTF-8") == msg
|
||||
|
||||
|
||||
@@ -5,10 +5,9 @@ import pickle
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
from io import StringIO
|
||||
from io import UnsupportedOperation
|
||||
|
||||
import py
|
||||
|
||||
import pytest
|
||||
from _pytest import capture
|
||||
from _pytest.capture import CaptureManager
|
||||
@@ -892,10 +891,10 @@ def test_dupfile_on_bytesio():
|
||||
|
||||
|
||||
def test_dupfile_on_textio():
|
||||
tio = py.io.TextIO()
|
||||
f = capture.safe_text_dupfile(tio, "wb")
|
||||
sio = StringIO()
|
||||
f = capture.safe_text_dupfile(sio, "wb")
|
||||
f.write("hello")
|
||||
assert tio.getvalue() == "hello"
|
||||
assert sio.getvalue() == "hello"
|
||||
assert not hasattr(f, "name")
|
||||
|
||||
|
||||
|
||||
@@ -1257,3 +1257,24 @@ def test_collector_respects_tbstyle(testdir):
|
||||
"*= 1 error in *",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_does_not_eagerly_collect_packages(testdir):
|
||||
testdir.makepyfile("def test(): pass")
|
||||
pydir = testdir.mkpydir("foopkg")
|
||||
pydir.join("__init__.py").write("assert False")
|
||||
result = testdir.runpytest()
|
||||
assert result.ret == ExitCode.OK
|
||||
|
||||
|
||||
def test_does_not_put_src_on_path(testdir):
|
||||
# `src` is not on sys.path so it should not be importable
|
||||
testdir.tmpdir.join("src/nope/__init__.py").ensure()
|
||||
testdir.makepyfile(
|
||||
"import pytest\n"
|
||||
"def test():\n"
|
||||
" with pytest.raises(ImportError):\n"
|
||||
" import nope\n"
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
assert result.ret == ExitCode.OK
|
||||
|
||||
@@ -482,7 +482,7 @@ class TestFunctional:
|
||||
items, rec = testdir.inline_genitems(p)
|
||||
base_item, sub_item, sub_item_other = items
|
||||
print(items, [x.nodeid for x in items])
|
||||
# new api seregates
|
||||
# new api segregates
|
||||
assert not list(base_item.iter_markers(name="b"))
|
||||
assert not list(sub_item_other.iter_markers(name="b"))
|
||||
assert list(sub_item.iter_markers(name="b"))
|
||||
|
||||
28
testing/test_meta.py
Normal file
28
testing/test_meta.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import pkgutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import _pytest
|
||||
import pytest
|
||||
|
||||
|
||||
def _modules():
|
||||
return sorted(
|
||||
n
|
||||
for _, n, _ in pkgutil.walk_packages(
|
||||
_pytest.__path__, prefix=_pytest.__name__ + "."
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("module", _modules())
|
||||
def test_no_warnings(module):
|
||||
# fmt: off
|
||||
subprocess.check_call((
|
||||
sys.executable,
|
||||
"-W", "error",
|
||||
# https://github.com/pytest-dev/pytest/issues/5901
|
||||
"-W", "ignore:The usage of `cmp` is deprecated and will be removed on or after 2021-06-01. Please use `eq` and `order` instead.:DeprecationWarning", # noqa: E501
|
||||
"-c", "import {}".format(module),
|
||||
))
|
||||
# fmt: on
|
||||
@@ -229,7 +229,7 @@ def test_nose_setup_ordering(testdir):
|
||||
|
||||
def test_apiwrapper_problem_issue260(testdir):
|
||||
# this would end up trying a call an optional teardown on the class
|
||||
# for plain unittests we dont want nose behaviour
|
||||
# for plain unittests we don't want nose behaviour
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import unittest
|
||||
|
||||
@@ -304,7 +304,7 @@ def test_argcomplete(testdir, monkeypatch):
|
||||
shlex.quote(sys.executable)
|
||||
)
|
||||
)
|
||||
# alternative would be exteneded Testdir.{run(),_run(),popen()} to be able
|
||||
# alternative would be extended Testdir.{run(),_run(),popen()} to be able
|
||||
# to handle a keyword argument env that replaces os.environ in popen or
|
||||
# extends the copy, advantage: could not forget to restore
|
||||
monkeypatch.setenv("_ARGCOMPLETE", "1")
|
||||
|
||||
@@ -17,6 +17,14 @@ else:
|
||||
_ENVIRON_PYTHONBREAKPOINT = os.environ.get("PYTHONBREAKPOINT", "")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def pdb_env(request):
|
||||
if "testdir" in request.fixturenames:
|
||||
# Disable pdb++ with inner tests.
|
||||
testdir = request.getfixturevalue("testdir")
|
||||
testdir._env_run_update["PDBPP_HIJACK_PDB"] = "0"
|
||||
|
||||
|
||||
def runpdb_and_get_report(testdir, source):
|
||||
p = testdir.makepyfile(source)
|
||||
result = testdir.runpytest_inprocess("--pdb", p)
|
||||
@@ -573,7 +581,7 @@ class TestPDB:
|
||||
# No extra newline.
|
||||
assert child.before.endswith(b"c\r\nprint_from_foo\r\n")
|
||||
|
||||
# set_debug should not raise outcomes.Exit, if used recrursively.
|
||||
# set_debug should not raise outcomes. Exit, if used recursively.
|
||||
child.sendline("debug 42")
|
||||
child.sendline("q")
|
||||
child.expect("LEAVING RECURSIVE DEBUGGER")
|
||||
@@ -1017,6 +1025,51 @@ class TestTraceOption:
|
||||
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
|
||||
TestPDB.flush(child)
|
||||
|
||||
def test_trace_with_parametrize_handles_shared_fixtureinfo(self, testdir):
|
||||
p1 = testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
@pytest.mark.parametrize('myparam', [1,2])
|
||||
def test_1(myparam, request):
|
||||
assert myparam in (1, 2)
|
||||
assert request.function.__name__ == "test_1"
|
||||
@pytest.mark.parametrize('func', [1,2])
|
||||
def test_func(func, request):
|
||||
assert func in (1, 2)
|
||||
assert request.function.__name__ == "test_func"
|
||||
@pytest.mark.parametrize('myparam', [1,2])
|
||||
def test_func_kw(myparam, request, func="func_kw"):
|
||||
assert myparam in (1, 2)
|
||||
assert func == "func_kw"
|
||||
assert request.function.__name__ == "test_func_kw"
|
||||
"""
|
||||
)
|
||||
child = testdir.spawn_pytest("--trace " + str(p1))
|
||||
for func, argname in [
|
||||
("test_1", "myparam"),
|
||||
("test_func", "func"),
|
||||
("test_func_kw", "myparam"),
|
||||
]:
|
||||
child.expect_exact("> PDB runcall (IO-capturing turned off) >")
|
||||
child.expect_exact(func)
|
||||
child.expect_exact("Pdb")
|
||||
child.sendline("args")
|
||||
child.expect_exact("{} = 1\r\n".format(argname))
|
||||
child.expect_exact("Pdb")
|
||||
child.sendline("c")
|
||||
child.expect_exact("Pdb")
|
||||
child.sendline("args")
|
||||
child.expect_exact("{} = 2\r\n".format(argname))
|
||||
child.expect_exact("Pdb")
|
||||
child.sendline("c")
|
||||
child.expect_exact("> PDB continue (IO-capturing resumed) >")
|
||||
rest = child.read().decode("utf8")
|
||||
assert "6 passed in" in rest
|
||||
assert "reading from stdin while output" not in rest
|
||||
# Only printed once - not on stderr.
|
||||
assert "Exit: Quitting debugger" not in child.before.decode("utf8")
|
||||
TestPDB.flush(child)
|
||||
|
||||
|
||||
def test_trace_after_runpytest(testdir):
|
||||
"""Test that debugging's pytest_configure is re-entrant."""
|
||||
@@ -1142,7 +1195,6 @@ def test_pdbcls_via_local_module(testdir):
|
||||
|
||||
def runcall(self, *args, **kwds):
|
||||
print("runcall_called", args, kwds)
|
||||
assert "func" in kwds
|
||||
""",
|
||||
)
|
||||
result = testdir.runpytest(
|
||||
|
||||
@@ -133,17 +133,17 @@ class TestReportSerialization:
|
||||
"""
|
||||
reprec = testdir.inline_runsource(
|
||||
"""
|
||||
import py
|
||||
import pytest
|
||||
def test_pass(): pass
|
||||
def test_fail(): 0/0
|
||||
@py.test.mark.skipif("True")
|
||||
@pytest.mark.skipif("True")
|
||||
def test_skip(): pass
|
||||
def test_skip_imperative():
|
||||
py.test.skip("hello")
|
||||
@py.test.mark.xfail("True")
|
||||
pytest.skip("hello")
|
||||
@pytest.mark.xfail("True")
|
||||
def test_xfail(): 0/0
|
||||
def test_xfail_imperative():
|
||||
py.test.xfail("hello")
|
||||
pytest.xfail("hello")
|
||||
"""
|
||||
)
|
||||
reports = reprec.getreports("pytest_runtest_logreport")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
|
||||
import py
|
||||
from io import StringIO
|
||||
|
||||
import _pytest._code
|
||||
import pytest
|
||||
@@ -13,7 +12,7 @@ pytestmark = pytest.mark.filterwarnings("ignore:--result-log is deprecated")
|
||||
|
||||
def test_write_log_entry():
|
||||
reslog = ResultLog(None, None)
|
||||
reslog.logfile = py.io.TextIO()
|
||||
reslog.logfile = StringIO()
|
||||
reslog.write_log_entry("name", ".", "")
|
||||
entry = reslog.logfile.getvalue()
|
||||
assert entry[-1] == "\n"
|
||||
@@ -21,7 +20,7 @@ def test_write_log_entry():
|
||||
assert len(entry_lines) == 1
|
||||
assert entry_lines[0] == ". name"
|
||||
|
||||
reslog.logfile = py.io.TextIO()
|
||||
reslog.logfile = StringIO()
|
||||
reslog.write_log_entry("name", "s", "Skipped")
|
||||
entry = reslog.logfile.getvalue()
|
||||
assert entry[-1] == "\n"
|
||||
@@ -30,7 +29,7 @@ def test_write_log_entry():
|
||||
assert entry_lines[0] == "s name"
|
||||
assert entry_lines[1] == " Skipped"
|
||||
|
||||
reslog.logfile = py.io.TextIO()
|
||||
reslog.logfile = StringIO()
|
||||
reslog.write_log_entry("name", "s", "Skipped\n")
|
||||
entry = reslog.logfile.getvalue()
|
||||
assert entry[-1] == "\n"
|
||||
@@ -39,7 +38,7 @@ def test_write_log_entry():
|
||||
assert entry_lines[0] == "s name"
|
||||
assert entry_lines[1] == " Skipped"
|
||||
|
||||
reslog.logfile = py.io.TextIO()
|
||||
reslog.logfile = StringIO()
|
||||
longrepr = " tb1\n tb 2\nE tb3\nSome Error"
|
||||
reslog.write_log_entry("name", "F", longrepr)
|
||||
entry = reslog.logfile.getvalue()
|
||||
@@ -118,7 +117,7 @@ class TestWithFunctionIntegration:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
excinfo = _pytest._code.ExceptionInfo.from_current()
|
||||
reslog = ResultLog(None, py.io.TextIO())
|
||||
reslog = ResultLog(None, StringIO())
|
||||
reslog.pytest_internalerror(excinfo.getrepr(style=style))
|
||||
entry = reslog.logfile.getvalue()
|
||||
entry_lines = entry.splitlines()
|
||||
|
||||
@@ -567,9 +567,19 @@ def test_pytest_exit_msg(testdir):
|
||||
result.stderr.fnmatch_lines(["Exit: oh noes"])
|
||||
|
||||
|
||||
def _strip_resource_warnings(lines):
|
||||
# Assert no output on stderr, except for unreliable ResourceWarnings.
|
||||
# (https://github.com/pytest-dev/pytest/issues/5088)
|
||||
return [
|
||||
x
|
||||
for x in lines
|
||||
if not x.startswith(("Exception ignored in:", "ResourceWarning"))
|
||||
]
|
||||
|
||||
|
||||
def test_pytest_exit_returncode(testdir):
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
"""\
|
||||
import pytest
|
||||
def test_foo():
|
||||
pytest.exit("some exit msg", 99)
|
||||
@@ -577,19 +587,13 @@ def test_pytest_exit_returncode(testdir):
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*! *Exit: some exit msg !*"])
|
||||
# Assert no output on stderr, except for unreliable ResourceWarnings.
|
||||
# (https://github.com/pytest-dev/pytest/issues/5088)
|
||||
assert [
|
||||
x
|
||||
for x in result.stderr.lines
|
||||
if not x.startswith("Exception ignored in:")
|
||||
and not x.startswith("ResourceWarning")
|
||||
] == [""]
|
||||
|
||||
assert _strip_resource_warnings(result.stderr.lines) == [""]
|
||||
assert result.ret == 99
|
||||
|
||||
# It prints to stderr also in case of exit during pytest_sessionstart.
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
"""\
|
||||
import pytest
|
||||
|
||||
def pytest_sessionstart():
|
||||
@@ -598,7 +602,10 @@ def test_pytest_exit_returncode(testdir):
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*! *Exit: during_sessionstart !*"])
|
||||
assert result.stderr.lines == ["Exit: during_sessionstart", ""]
|
||||
assert _strip_resource_warnings(result.stderr.lines) == [
|
||||
"Exit: during_sessionstart",
|
||||
"",
|
||||
]
|
||||
assert result.ret == 98
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import pytest
|
||||
@pytest.fixture
|
||||
def stepwise_testdir(testdir):
|
||||
# Rather than having to modify our testfile between tests, we introduce
|
||||
# a flag for wether or not the second test should fail.
|
||||
# a flag for whether or not the second test should fail.
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
def pytest_addoption(parser):
|
||||
|
||||
@@ -5,6 +5,7 @@ import collections
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
from io import StringIO
|
||||
|
||||
import pluggy
|
||||
import py
|
||||
@@ -268,7 +269,7 @@ class TestTerminal:
|
||||
|
||||
def test_rewrite(self, testdir, monkeypatch):
|
||||
config = testdir.parseconfig()
|
||||
f = py.io.TextIO()
|
||||
f = StringIO()
|
||||
monkeypatch.setattr(f, "isatty", lambda *args: True)
|
||||
tr = TerminalReporter(config, f)
|
||||
tr._tw.fullwidth = 10
|
||||
|
||||
@@ -383,6 +383,10 @@ class TestRmRf:
|
||||
on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
|
||||
assert fn.is_file()
|
||||
|
||||
# we ignore FileNotFoundError
|
||||
exc_info = (None, FileNotFoundError(), None)
|
||||
assert not on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)
|
||||
|
||||
# unknown function
|
||||
with pytest.warns(pytest.PytestWarning):
|
||||
exc_info = (None, PermissionError(), None)
|
||||
|
||||
4
tox.ini
4
tox.ini
@@ -41,6 +41,8 @@ setenv =
|
||||
xdist: _PYTEST_TOX_POSARGS_XDIST=-n auto
|
||||
extras = testing
|
||||
deps =
|
||||
oldattrs: attrs==17.4.0
|
||||
oldattrs: hypothesis<=4.38.1
|
||||
numpy: numpy
|
||||
pexpect: pexpect
|
||||
pluggymaster: git+https://github.com/pytest-dev/pluggy.git@master
|
||||
@@ -140,6 +142,8 @@ filterwarnings =
|
||||
error
|
||||
default:Using or importing the ABCs:DeprecationWarning:unittest2.*
|
||||
ignore:Module already imported so cannot be rewritten:pytest.PytestWarning
|
||||
# https://github.com/pytest-dev/pytest/issues/5974
|
||||
default:\(rm_rf\) error removing.*:pytest.PytestWarning
|
||||
# produced by python3.6/site.py itself (3.6.7 on Travis, could not trigger it with 3.6.8).
|
||||
ignore:.*U.*mode is deprecated:DeprecationWarning:(?!(pytest|_pytest))
|
||||
# produced by pytest-xdist
|
||||
|
||||
Reference in New Issue
Block a user