Merge with upstream/master

This commit is contained in:
Bruno Oliveira 2018-07-11 20:40:30 -03:00
commit 251adbf644
36 changed files with 184 additions and 107 deletions

View File

@ -34,3 +34,8 @@ repos:
language: python
additional_dependencies: [pygments, restructuredtext_lint]
python_version: python3.6
- id: rst-backticks
name: rst ``code`` is two backticks
entry: ' `[^`]+[^_]`([^_]|$)'
language: pygrep
types: [rst]

View File

@ -3,7 +3,8 @@ language: python
stages:
- linting
- test
- deploy
- name: deploy
if: repo = pytest-dev/pytest AND tag IS present
python:
- '3.6'
install:

View File

@ -8,6 +8,52 @@
.. towncrier release notes start
Pytest 3.6.3 (2018-07-04)
=========================
Bug Fixes
---------
- Fix ``ImportWarning`` triggered by explicit relative imports in
assertion-rewritten package modules. (`#3061
<https://github.com/pytest-dev/pytest/issues/3061>`_)
- Fix error in ``pytest.approx`` when dealing with 0-dimension numpy
arrays. (`#3593 <https://github.com/pytest-dev/pytest/issues/3593>`_)
- No longer raise ``ValueError`` when using the ``get_marker`` API. (`#3605
<https://github.com/pytest-dev/pytest/issues/3605>`_)
- Fix problem where log messages with non-ascii characters would not
appear in the output log file.
(`#3630 <https://github.com/pytest-dev/pytest/issues/3630>`_)
- No longer raise ``AttributeError`` when legacy marks can't be stored in
functions. (`#3631 <https://github.com/pytest-dev/pytest/issues/3631>`_)
Improved Documentation
----------------------
- The description above the example for ``@pytest.mark.skipif`` now better
matches the code. (`#3611
<https://github.com/pytest-dev/pytest/issues/3611>`_)
Trivial/Internal Changes
------------------------
- Internal refactoring: removed unused ``CallSpec2tox ._globalid_args``
attribute and ``metafunc`` parameter from ``CallSpec2.copy()``. (`#3598
<https://github.com/pytest-dev/pytest/issues/3598>`_)
- Silence usage of ``reduce`` warning in Python 2 (`#3609
<https://github.com/pytest-dev/pytest/issues/3609>`_)
- Fix usage of ``attr.ib`` deprecated ``convert`` parameter. (`#3653
<https://github.com/pytest-dev/pytest/issues/3653>`_)
Pytest 3.6.2 (2018-06-20)
=========================
@ -26,7 +72,7 @@ Bug Fixes
raises an exception. (`#3569
<https://github.com/pytest-dev/pytest/issues/3569>`_)
- Fix encoding error with `print` statements in doctests (`#3583
- Fix encoding error with ``print`` statements in doctests (`#3583
<https://github.com/pytest-dev/pytest/issues/3583>`_)
@ -299,7 +345,7 @@ Features
``pytest_runtest_logfinish`` hooks when live logs are enabled. (`#3189
<https://github.com/pytest-dev/pytest/issues/3189>`_)
- Passing `--log-cli-level` in the command-line now automatically activates
- Passing ``--log-cli-level`` in the command-line now automatically activates
live logging. (`#3190 <https://github.com/pytest-dev/pytest/issues/3190>`_)
- Add command line option ``--deselect`` to allow deselection of individual
@ -651,8 +697,8 @@ Trivial/Internal Changes
- Code cleanup. (`#3015 <https://github.com/pytest-dev/pytest/issues/3015>`_,
`#3021 <https://github.com/pytest-dev/pytest/issues/3021>`_)
- Clean up code by replacing imports and references of `_ast` to `ast`. (`#3018
<https://github.com/pytest-dev/pytest/issues/3018>`_)
- Clean up code by replacing imports and references of ``_ast`` to ``ast``.
(`#3018 <https://github.com/pytest-dev/pytest/issues/3018>`_)
Pytest 3.3.1 (2017-12-05)
@ -980,7 +1026,7 @@ Pytest 3.2.2 (2017-09-06)
Bug Fixes
---------
- Calling the deprecated `request.getfuncargvalue()` now shows the source of
- Calling the deprecated ``request.getfuncargvalue()`` now shows the source of
the call. (`#2681 <https://github.com/pytest-dev/pytest/issues/2681>`_)
- Allow tests declared as ``@staticmethod`` to use fixtures. (`#2699
@ -1002,10 +1048,10 @@ Improved Documentation
``pytest.mark.MARKER_NAME.__call__`` (`#2604
<https://github.com/pytest-dev/pytest/issues/2604>`_)
- In one of the simple examples, use `pytest_collection_modifyitems()` to skip
- In one of the simple examples, use ``pytest_collection_modifyitems()`` to skip
tests based on a command-line option, allowing its sharing while preventing a
user error when acessing `pytest.config` before the argument parsing. (`#2653
<https://github.com/pytest-dev/pytest/issues/2653>`_)
user error when acessing ``pytest.config`` before the argument parsing.
(`#2653 <https://github.com/pytest-dev/pytest/issues/2653>`_)
Trivial/Internal Changes
@ -1083,7 +1129,7 @@ Features
from parent classes or modules. (`#2516 <https://github.com/pytest-
dev/pytest/issues/2516>`_)
- Collection ignores local virtualenvs by default; `--collect-in-virtualenv`
- Collection ignores local virtualenvs by default; ``--collect-in-virtualenv``
overrides this behavior. (`#2518 <https://github.com/pytest-
dev/pytest/issues/2518>`_)

View File

@ -10,10 +10,6 @@ taking a lot of time to make a new one.
pytest releases must be prepared on **Linux** because the docs and examples expect
to be executed in that platform.
#. Install development dependencies in a virtual environment with::
pip3 install -U -r tasks/requirements.txt
#. Create a branch ``release-X.Y.Z`` with the version for the release.
* **patch releases**: from the latest ``master``;
@ -22,9 +18,19 @@ taking a lot of time to make a new one.
Ensure your are in a clean work tree.
#. Generate docs, changelog, announcements and a **local** tag::
#. Install development dependencies in a virtual environment with::
$ pip3 install -U -r tasks/requirements.txt
#. Generate docs, changelog, announcements, and a **local** tag::
$ invoke generate.pre-release <VERSION>
#. Execute pre-commit on all files to ensure the docs are conformant and commit your results::
$ pre-commit run --all-files
$ git commit -am "Fix files with pre-commit"
invoke generate.pre-release <VERSION>
#. Open a PR for this branch targeting ``master``.

View File

@ -3,6 +3,7 @@
:align: center
:alt: pytest
------
.. image:: https://img.shields.io/pypi/v/pytest.svg
@ -109,7 +110,7 @@ Consult the `Changelog <http://docs.pytest.org/en/latest/changelog.html>`__ page
License
-------
Copyright Holger Krekel and others, 2004-2017.
Copyright Holger Krekel and others, 2004-2018.
Distributed under the terms of the `MIT`_ license, pytest is free and open source software.

View File

@ -0,0 +1 @@
Remove obsolete ``__future__`` imports.

View File

@ -1 +0,0 @@
Fix ``ImportWarning`` triggered by explicit relative imports in assertion-rewritten package modules.

View File

@ -1,5 +0,0 @@
If the user pass as a expected value a numpy array created like
numpy.array(5); it will creates an array with one element without shape,
when used with approx it will raise an error for the `repr`
'TypeError: iteration over a 0-d array'. With this PR pytest will iterate
properly in the numpy array even with 0 dimension.

View File

@ -1 +0,0 @@
Internal refactoring: removed unused ``CallSpec2tox ._globalid_args`` attribute and ``metafunc`` parameter from ``CallSpec2.copy()``.

View File

@ -1 +0,0 @@
no longer ValueError when using the ``get_marker`` api.

View File

@ -1 +0,0 @@
Silence usage of ``reduce`` warning in python 2

View File

@ -1 +0,0 @@
The description above the example for ``@pytest.mark.skipif`` now better matches the code.

View File

@ -1 +0,0 @@
Log messages with unicode characters would not appear in the output log file.

View File

@ -1 +0,0 @@
No longer raise AttributeError when legacy marks can't be stored.

1
changelog/742.bugfix.rst Normal file
View File

@ -0,0 +1 @@
Invoke pytest using ``-mpytest`` so ``sys.path`` does not get polluted by packages installed in ``site-packages``.

View File

@ -6,6 +6,7 @@ Release announcements
:maxdepth: 2
release-3.6.3
release-3.6.2
release-3.6.1
release-3.6.0

View File

@ -124,7 +124,7 @@ The py.test Development Team
Thanks `@biern`_ for the PR.
* Fix `traceback style docs`_ to describe all of the available options
(auto/long/short/line/native/no), with `auto` being the default since v2.6.
(auto/long/short/line/native/no), with ``auto`` being the default since v2.6.
Thanks `@hackebrot`_ for the PR.
* Fix (`#1422`_): junit record_xml_property doesn't allow multiple records

View File

@ -0,0 +1,28 @@
pytest-3.6.3
=======================================
pytest 3.6.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 http://doc.pytest.org/en/latest/changelog.html.
Thanks to all who contributed to this release, among them:
* AdamEr8
* Anthony Sottile
* Bruno Oliveira
* Jean-Paul Calderone
* Jon Dufresne
* Marcelo Duarte Trevisani
* Ondřej Súkup
* Ronny Pfannschmidt
* T.E.A de Souza
* Victor
* victor
Happy testing,
The pytest Development Team

View File

@ -299,10 +299,10 @@ Skip and xfail marks can also be applied in this way, see :ref:`skip/xfail with
.. note::
If the data you are parametrizing happen to be single callables, you need to be careful
when marking these items. `pytest.mark.xfail(my_func)` won't work because it's also the
when marking these items. ``pytest.mark.xfail(my_func)`` won't work because it's also the
signature of a function being decorated. To resolve this ambiguity, you need to pass a
reason argument:
`pytest.mark.xfail(func_bar, reason="Issue#7")`.
``pytest.mark.xfail(func_bar, reason="Issue#7")``.
.. _`adding a custom marker from a plugin`:

View File

@ -415,8 +415,8 @@ Now we can profile which test functions execute the slowest::
========================= slowest 3 test durations =========================
0.30s call test_some_are_slow.py::test_funcslow2
0.21s call test_some_are_slow.py::test_funcslow1
0.10s call test_some_are_slow.py::test_funcfast
0.20s call test_some_are_slow.py::test_funcslow1
0.13s call test_some_are_slow.py::test_funcfast
========================= 3 passed in 0.12 seconds =========================
incremental testing - test steps

View File

@ -944,7 +944,7 @@ a generic feature of the mark mechanism:
Note that the assigned variable *must* be called ``pytestmark``, assigning e.g.
``foomark`` will not activate the fixtures.
Lastly you can put fixtures required by all tests in your project
It is also possible to put fixtures required by all tests in your project
into an ini-file:
.. code-block:: ini
@ -954,6 +954,22 @@ into an ini-file:
usefixtures = cleandir
.. warning::
Note this mark has no effect in **fixture functions**. For example,
this **will not work as expected**:
.. code-block:: python
@pytest.mark.usefixtures("my_other_fixture")
@pytest.fixture
def my_fixture_that_sadly_wont_use_my_other_fixture():
...
Currently this will not generate any error or warning, but this is intended
to be handled by `#3664 <https://github.com/pytest-dev/pytest/issues/3664>`_.
.. _`autouse`:
.. _`autouse fixtures`:

View File

@ -187,7 +187,7 @@ You can then install your package in "editable" mode::
pip install -e .
which lets you change your source code (both tests and application) and rerun tests at will.
This is similar to running `python setup.py develop` or `conda develop` in that it installs
This is similar to running ``python setup.py develop`` or ``conda develop`` in that it installs
your package using a symlink to your development code.
Once you are done with your work and want to make sure that your actual

View File

@ -52,8 +52,6 @@ should add ``--strict`` to ``addopts``:
serial
.. `marker-iteration`
Marker revamp and iteration
---------------------------

View File

@ -161,6 +161,25 @@ Skip a test function if a condition is ``True``.
:keyword str reason: Reason why the test function is being skipped.
.. _`pytest.mark.usefixtures ref`:
pytest.mark.usefixtures
~~~~~~~~~~~~~~~~~~~~~~~
**Tutorial**: :ref:`usefixtures`.
Mark a test function as using the given fixture names.
.. warning::
This mark can be used with *test functions* only, having no affect when applied
to a **fixture** function.
.. py:function:: pytest.mark.usefixtures(*names)
:param args: the names of the fixture to use, as strings
.. _`pytest.mark.xfail ref`:
pytest.mark.xfail

View File

@ -1,4 +1,4 @@
from __future__ import absolute_import, division, generators, print_function
from __future__ import absolute_import, division, print_function
import ast
from ast import PyCF_ONLY_AST as _AST_FLAG
@ -152,12 +152,7 @@ class Source(object):
return "\n".join(self.lines)
def compile(
self,
filename=None,
mode="exec",
flag=generators.compiler_flag,
dont_inherit=0,
_genframe=None,
self, filename=None, mode="exec", flag=0, dont_inherit=0, _genframe=None
):
""" return compiled code object. if filename is None
invent an artificial filename which displays
@ -201,9 +196,7 @@ class Source(object):
#
def compile_(
source, filename=None, mode="exec", flags=generators.compiler_flag, dont_inherit=0
):
def compile_(source, filename=None, mode="exec", flags=0, dont_inherit=0):
""" compile the given source to a raw code object,
and maintain an internal cache which allows later
retrieval of the source code for the code object

View File

@ -41,8 +41,8 @@ PY36 = sys.version_info[:2] >= (3, 6)
MODULE_NOT_FOUND_ERROR = "ModuleNotFoundError" if PY36 else "ImportError"
if _PY3:
from collections.abc import MutableMapping as MappingMixin # noqa
from collections.abc import Mapping, Sequence # noqa
from collections.abc import MutableMapping as MappingMixin
from collections.abc import Mapping, Sequence
else:
# those raise DeprecationWarnings in Python >=3.7
from collections import MutableMapping as MappingMixin # noqa

View File

@ -71,7 +71,7 @@ def main(args=None, plugins=None):
return 4
class cmdline(object): # NOQA compatibility namespace
class cmdline(object): # compatibility namespace
main = staticmethod(main)

View File

@ -294,7 +294,7 @@ def _marked(func, mark):
class MarkInfo(object):
""" Marking object created by :class:`MarkDecorator` instances. """
_marks = attr.ib(convert=list)
_marks = attr.ib(converter=list)
@_marks.validator
def validate_marks(self, attribute, value):

View File

@ -23,11 +23,6 @@ from _pytest.main import Session, EXIT_OK
from _pytest.assertion.rewrite import AssertionRewritingHook
PYTEST_FULLPATH = os.path.abspath(pytest.__file__.rstrip("oc")).replace(
"$py.class", ".py"
)
IGNORE_PAM = [ # filenames added when obtaining details about the current user
u"/var/lib/sss/mc/passwd"
]
@ -1029,9 +1024,7 @@ class Testdir(object):
print("couldn't print to %s because of encoding" % (fp,))
def _getpytestargs(self):
# we cannot use `(sys.executable, script)` because on Windows the
# script is e.g. `pytest.exe`
return (sys.executable, PYTEST_FULLPATH) # noqa
return (sys.executable, "-mpytest")
def runpython(self, script):
"""Run a python script using sys.executable as interpreter.

View File

@ -744,3 +744,19 @@ something
'''"""
result = getstatement(1, source)
assert str(result) == "'''\n'''"
def test_getstartingblock_multiline():
class A(object):
def __init__(self, *args):
frame = sys._getframe(1)
self.source = _pytest._code.Frame(frame).statement
# fmt: off
x = A('x',
'y'
,
'z')
# fmt: on
values = [i for i in x.source.lines if i.strip()]
assert len(values) == 4

View File

@ -1,28 +0,0 @@
# flake8: noqa
import sys
import _pytest._code
def test_getstartingblock_multiline():
"""
This test was originally found in test_source.py, but it depends on the weird
formatting of the ``x = A`` construct seen here and our autopep8 tool can only exclude entire
files (it does not support excluding lines/blocks using the traditional #noqa comment yet,
see hhatto/autopep8#307). It was considered better to just move this single test to its own
file and exclude it from autopep8 than try to complicate things.
"""
class A(object):
def __init__(self, *args):
frame = sys._getframe(1)
self.source = _pytest._code.Frame(frame).statement
# fmt: off
x = A('x',
'y'
,
'z')
# fmt: on
values = [i for i in x.source.lines if i.strip()]
assert len(values) == 4

View File

@ -33,8 +33,7 @@ class TestRaises(object):
def test_raises_as_contextmanager(self, testdir):
testdir.makepyfile(
"""
from __future__ import with_statement
import py, pytest
import pytest
import _pytest._code
def test_simple():

View File

@ -97,7 +97,7 @@ class TestAssertionRewrite(object):
assert imp.lineno == 2
assert imp.col_offset == 0
assert isinstance(m.body[2], ast.Assign)
s = """from __future__ import with_statement\nother_stuff"""
s = """from __future__ import division\nother_stuff"""
m = rewrite(s)
assert isinstance(m.body[0], ast.ImportFrom)
for imp in m.body[1:3]:
@ -105,7 +105,7 @@ class TestAssertionRewrite(object):
assert imp.lineno == 2
assert imp.col_offset == 0
assert isinstance(m.body[3], ast.Expr)
s = """'doc string'\nfrom __future__ import with_statement"""
s = """'doc string'\nfrom __future__ import division"""
m = rewrite(s)
adjust_body_for_new_docstring_in_module_node(m)
assert isinstance(m.body[0], ast.ImportFrom)
@ -113,7 +113,7 @@ class TestAssertionRewrite(object):
assert isinstance(imp, ast.Import)
assert imp.lineno == 2
assert imp.col_offset == 0
s = """'doc string'\nfrom __future__ import with_statement\nother"""
s = """'doc string'\nfrom __future__ import division\nother"""
m = rewrite(s)
adjust_body_for_new_docstring_in_module_node(m)
assert isinstance(m.body[0], ast.ImportFrom)
@ -941,7 +941,7 @@ class TestAssertionRewriteHookDetails(object):
e = IOError()
e.errno = 10
raise e
yield # noqa
yield
monkeypatch.setattr(atomicwrites, "atomic_write", atomic_write_failed)
assert not _write_pyc(state, [1], source_path.stat(), pycpath)

View File

@ -2,7 +2,6 @@ from __future__ import absolute_import, division, print_function
# note: py.io capture tests where copied from
# pylib 1.4.20.dev2 (rev 13d9af95547e)
from __future__ import with_statement
import pickle
import os
import sys

View File

@ -364,10 +364,7 @@ class TestSysPathsSnapshot(object):
original = list(sys_path)
original_other = list(getattr(sys, other_path_type))
snapshot = SysPathsSnapshot()
transformation = {
"source": (0, 1, 2, 3, 4, 5),
"target": (6, 2, 9, 7, 5, 8),
} # noqa: E201
transformation = {"source": (0, 1, 2, 3, 4, 5), "target": (6, 2, 9, 7, 5, 8)}
assert sys_path == [self.path(x) for x in transformation["source"]]
sys_path[1] = self.path(6)
sys_path[3] = self.path(7)
@ -394,3 +391,8 @@ class TestSysPathsSnapshot(object):
assert getattr(sys, path_type) == original_data
assert getattr(sys, other_path_type) is original_other
assert getattr(sys, other_path_type) == original_other_data
def test_testdir_subprocess(testdir):
testfile = testdir.makepyfile("def test_one(): pass")
assert testdir.runpytest_subprocess(testfile).ret == 0

View File

@ -151,14 +151,6 @@ commands =
rm -rf /tmp/doc-exec*
make regen
[testenv:fix-lint]
skipsdist = True
usedevelop = True
deps =
autopep8
commands =
autopep8 --in-place -r --max-line-length=120 --exclude=test_source_multiline_block.py _pytest testing setup.py pytest.py
[testenv:jython]
changedir = testing
commands =