From 06bb61bbe31829955b36451829fdb9b4ffedc65b Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 20 Nov 2016 11:56:15 -0500 Subject: [PATCH 01/16] Don't fail if imp can't find the source for a .pyc file. #2038 --- AUTHORS | 1 + CHANGELOG.rst | 7 ++++++- _pytest/assertion/rewrite.py | 7 ++++++- testing/test_assertrewrite.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 6de0a112b7d..8cc6824cd95 100644 --- a/AUTHORS +++ b/AUTHORS @@ -101,6 +101,7 @@ Michael Birtwell Michael Droettboom Michael Seifert Mike Lundy +Ned Batchelder Nicolas Delaby Oleg Pidsadnyi Oliver Bestwalter diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 60875f4c4ee..b87302e8cf6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,12 +5,17 @@ * -* +* Cope gracefully with a .pyc file with no matching .py file (`#2038`_). Thanks + `@nedbat`_. * * +.. _@nedbat: https://github.com/nedbat + +.. _#2038: https://github.com/pytest-dev/pytest/issues/2038 + 3.0.4 ===== diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 6b4c1f48357..9136c386741 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -80,7 +80,12 @@ def find_module(self, name, path=None): tp = desc[2] if tp == imp.PY_COMPILED: if hasattr(imp, "source_from_cache"): - fn = imp.source_from_cache(fn) + try: + fn = imp.source_from_cache(fn) + except ValueError: + # Python 3 doesn't like orphaned but still-importable + # .pyc files. + fn = fn[:-1] else: fn = fn[:-1] elif tp != imp.PY_SOURCE: diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index e72266a18d7..ded11cbb4b0 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -1,7 +1,10 @@ +import glob import os +import py_compile import stat import sys import zipfile + import py import pytest @@ -480,6 +483,31 @@ def test_no_bytecode(): monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1") assert testdir.runpytest_subprocess().ret == 0 + def test_orphaned_pyc_file(self, testdir): + if sys.version_info < (3, 0) and hasattr(sys, 'pypy_version_info'): + pytest.skip("pypy2 doesn't run orphaned pyc files") + + testdir.makepyfile(""" + import orphan + def test_it(): + assert orphan.value == 17 + """) + testdir.makepyfile(orphan=""" + value = 17 + """) + py_compile.compile("orphan.py") + os.remove("orphan.py") + + # Python 3 puts the .pyc files in a __pycache__ directory, and will + # not import from there without source. It will import a .pyc from + # the source location though. + if not os.path.exists("orphan.pyc"): + pycs = glob.glob("__pycache__/orphan.*.pyc") + assert len(pycs) == 1 + os.rename(pycs[0], "orphan.pyc") + + assert testdir.runpytest().ret == 0 + @pytest.mark.skipif('"__pypy__" in sys.modules') def test_pyc_vs_pyo(self, testdir, monkeypatch): testdir.makepyfile(""" From 629d8e9fd62999ffbb80fcb8881c1c88e51d345f Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 23 Nov 2016 09:47:36 -0200 Subject: [PATCH 02/16] Show an error if --confcutdir is not a valid directory Fixes #2078 --- CHANGELOG.rst | 6 +++++- _pytest/config.py | 6 +++++- testing/test_config.py | 9 +++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b87302e8cf6..eeb41a648d6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,7 +3,10 @@ * -* +* An error message is now displayed if ``--confcutdir`` is not a valid directory, avoiding + subtle bugs (`#2078`_). + Thanks `@nicoddemus`_ for the PR. + * Cope gracefully with a .pyc file with no matching .py file (`#2038`_). Thanks `@nedbat`_. @@ -15,6 +18,7 @@ .. _@nedbat: https://github.com/nedbat .. _#2038: https://github.com/pytest-dev/pytest/issues/2038 +.. _#2078: https://github.com/pytest-dev/pytest/issues/2078 3.0.4 diff --git a/_pytest/config.py b/_pytest/config.py index ab5e1b99481..61123f6acc2 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -996,6 +996,7 @@ def _warn_about_missing_assertion(self, mode): "(are you using python -O?)\n") def _preparse(self, args, addopts=True): + import pytest self._initini(args) if addopts: args[:] = shlex.split(os.environ.get('PYTEST_ADDOPTS', '')) + args @@ -1007,7 +1008,10 @@ def _preparse(self, args, addopts=True): self.pluginmanager.load_setuptools_entrypoints(entrypoint_name) self.pluginmanager.consider_env() self.known_args_namespace = ns = self._parser.parse_known_args(args, namespace=self.option.copy()) - if self.known_args_namespace.confcutdir is None and self.inifile: + confcutdir = self.known_args_namespace.confcutdir + if confcutdir and not os.path.isdir(confcutdir): + raise pytest.UsageError('--confcutdir must be a directory, given: {0}'.format(confcutdir)) + if confcutdir is None and self.inifile: confcutdir = py.path.local(self.inifile).dirname self.known_args_namespace.confcutdir = confcutdir try: diff --git a/testing/test_config.py b/testing/test_config.py index 75a806c4a99..1567dd27ca0 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -294,6 +294,15 @@ def pytest_addoption(parser): assert len(l) == 2 assert l == ["456", "123"] + def test_confcutdir_check_isdir(self, testdir): + """Give an error if --confcutdir is not a valid directory (#2078)""" + with pytest.raises(pytest.UsageError): + testdir.parseconfig('--confcutdir', testdir.tmpdir.join('file').ensure(file=1)) + with pytest.raises(pytest.UsageError): + testdir.parseconfig('--confcutdir', testdir.tmpdir.join('inexistant')) + config = testdir.parseconfig('--confcutdir', testdir.tmpdir.join('dir').ensure(dir=1)) + assert config.getoption('confcutdir') == str(testdir.tmpdir.join('dir')) + class TestConfigFromdictargs: def test_basic_behavior(self): From 33c0b06fdf989d8df63dc68ba5336ecad2eadd30 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 24 Nov 2016 15:27:38 -0200 Subject: [PATCH 03/16] Fix error in approx's repr with complex numbers Fix #2082 --- CHANGELOG.rst | 6 ++++++ _pytest/python.py | 3 +++ testing/python/approx.py | 1 + 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index eeb41a648d6..f97ff3787b9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,10 @@ subtle bugs (`#2078`_). Thanks `@nicoddemus`_ for the PR. +* Fix error message using ``approx`` with complex numbers (`#2082`_). + Thanks `@adler-j`_ for the report and `@nicoddemus`_ for the PR. + +* * Cope gracefully with a .pyc file with no matching .py file (`#2038`_). Thanks `@nedbat`_. @@ -15,10 +19,12 @@ * +.. _@adler-j: https://github.com/adler-j .. _@nedbat: https://github.com/nedbat .. _#2038: https://github.com/pytest-dev/pytest/issues/2038 .. _#2078: https://github.com/pytest-dev/pytest/issues/2078 +.. _#2082: https://github.com/pytest-dev/pytest/issues/2082 3.0.4 diff --git a/_pytest/python.py b/_pytest/python.py index 88c65b1ce4e..76cf4bd6401 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1419,6 +1419,9 @@ def __init__(self, expected, rel=None, abs=None): self.rel = rel def __repr__(self): + if isinstance(self.expected, complex): + return str(self.expected) + # Infinities aren't compared using tolerances, so don't show a # tolerance. if math.isinf(self.expected): diff --git a/testing/python/approx.py b/testing/python/approx.py index 2720c573f54..d6bb1f9cf52 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -28,6 +28,7 @@ def test_repr_string(self): print(approx(inf)) print(approx(1.0, rel=nan)) print(approx(1.0, rel=inf)) + print(approx(1.0j, rel=inf)) def test_operator_overloading(self): assert 1 == approx(1, rel=1e-6, abs=1e-12) From 8763590eefe7d1e5e2668bcb4a057f726f5e4a0e Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 24 Nov 2016 16:08:51 -0200 Subject: [PATCH 04/16] Only execute "coveralls" toxenv on master once Just noticed that the "coveralls" env was being execute after each env. This was introduced by mistake in #2056 --- appveyor.yml | 9 ++++----- scripts/call-tox.bat | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 scripts/call-tox.bat diff --git a/appveyor.yml b/appveyor.yml index 7192ec06fb6..a42aa16dc80 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,6 +6,8 @@ environment: # https://www.appveyor.com/docs/build-configuration#secure-variables matrix: + # coveralls is not in the default env list + - TOXENV: "coveralls" # note: please use "tox --listenvs" to populate the build matrix below - TOXENV: "linting" - TOXENV: "py26" @@ -29,14 +31,11 @@ install: - echo Installed Pythons - dir c:\Python* - - if "%TOXENV%" == "pypy" scripts\install-pypy.bat + - if "%TOXENV%" == "pypy" call scripts\install-pypy.bat - C:\Python35\python -m pip install tox build: false # Not a C# project, build stuff at the test step instead. test_script: - - C:\Python35\python -m tox - # coveralls is not in tox's envlist, plus for PRs the secure variable - # is not defined so we have to check for it - - if defined COVERALLS_REPO_TOKEN C:\Python35\python -m tox -e coveralls + - call scripts\call-tox.bat diff --git a/scripts/call-tox.bat b/scripts/call-tox.bat new file mode 100644 index 00000000000..3ca9eb6d717 --- /dev/null +++ b/scripts/call-tox.bat @@ -0,0 +1,8 @@ +REM skip "coveralls" run in PRs or forks +if "%TOXENV%" == "coveralls" ( + if not defined COVERALLS_REPO_TOKEN ( + echo skipping coveralls run because COVERALLS_REPO_TOKEN is not defined + exit /b 0 + ) +) +C:\Python35\python -m tox From c1b83cdeea9763635bc182ab7f8c94aae3d4c4ad Mon Sep 17 00:00:00 2001 From: Duncan Betts Date: Sat, 26 Nov 2016 10:47:15 +0000 Subject: [PATCH 05/16] Add hint of Issue #478 to error text --- AUTHORS | 1 + CHANGELOG.rst | 4 +++- _pytest/main.py | 5 ++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index 8cc6824cd95..e966139bec3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -44,6 +44,7 @@ David Mohr David Vierra Diego Russo Dmitry Dygalo +Duncan Betts Edison Gustavo Muenz Edoardo Batini Eduardo Schettino diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f97ff3787b9..40797c30c6e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ 3.0.5.dev0 ========== -* +* Add hint to error message hinting possible missing __init__.py (`#478`_). Thanks `@DuncanBetts`_. * An error message is now displayed if ``--confcutdir`` is not a valid directory, avoiding subtle bugs (`#2078`_). @@ -20,8 +20,10 @@ * .. _@adler-j: https://github.com/adler-j +.. _@DuncanBetts: https://github.com/DuncanBetts .. _@nedbat: https://github.com/nedbat +.. _#478: https://github.com/pytest-dev/pytest/issues/478 .. _#2038: https://github.com/pytest-dev/pytest/issues/2038 .. _#2078: https://github.com/pytest-dev/pytest/issues/2078 .. _#2082: https://github.com/pytest-dev/pytest/issues/2082 diff --git a/_pytest/main.py b/_pytest/main.py index 5771a169999..dd0775501a1 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -704,10 +704,9 @@ def _parsearg(self, arg): path = self.config.invocation_dir.join(relpath, abs=True) if not path.check(): if self.config.option.pyargs: - msg = "file or package not found: " + raise pytest.UsageError("file or package not found: " + arg + " (missing __init__.py?)") else: - msg = "file not found: " - raise pytest.UsageError(msg + arg) + raise pytest.UsageError("file not found: " + arg) parts[0] = path return parts From 2e6a58ab6981ce5bed1becf5239951654166ccbb Mon Sep 17 00:00:00 2001 From: Ana Vojnovic Date: Sat, 26 Nov 2016 15:04:52 +0100 Subject: [PATCH 06/16] Clarify test discovery docs. --- doc/en/goodpractices.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/en/goodpractices.rst b/doc/en/goodpractices.rst index 2a5d4d7c8e6..d1e3e66fdd9 100644 --- a/doc/en/goodpractices.rst +++ b/doc/en/goodpractices.rst @@ -16,10 +16,12 @@ Conventions for Python test discovery * If no arguments are specified then collection starts from :confval:`testpaths` (if configured) or the current directory. Alternatively, command line arguments can be used in any combination of directories, file names or node ids. -* recurse into directories, unless they match :confval:`norecursedirs` -* ``test_*.py`` or ``*_test.py`` files, imported by their `test package name`_. -* ``Test`` prefixed test classes (without an ``__init__`` method) -* ``test_`` prefixed test functions or methods are test items +* Recurse into directories, unless they match :confval:`norecursedirs`. +* In those directories, search for ``test_*.py`` or ``*_test.py`` files, imported by their `test package name`_. +* From those files, collect test items: + + * ``test_`` prefixed test functions or methods outside of class + * ``test_`` prefixed test functions or methods inside ``Test`` prefixed test classes (without an ``__init__`` method) For examples of how to customize your test discovery :doc:`example/pythoncollection`. From 61205701981d9d27e0bd0209f2bf577156eb01d5 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 26 Nov 2016 14:49:31 -0200 Subject: [PATCH 07/16] Pin setuptools to < 29 because of AppVeyor failures Related to pypa/setuptools#861 Remove the pin when we have a new setuptools release --- tox.ini | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index c2f866f265d..f0c8e93d4f5 100644 --- a/tox.ini +++ b/tox.ini @@ -117,7 +117,10 @@ commands= basepython = python usedevelop=True skipsdist=True -deps=PyYAML +deps= + PyYAML + # pinning setuptools because of AppVeyor failures, see pypa/setuptools#861 + setuptools<29.0.0 commands= pytest -rfsxX doc/en pytest --doctest-modules {toxinidir}/_pytest From 1aa5bfea11e00ebc1e288f5ad818d937c03caef4 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sat, 26 Nov 2016 12:25:42 +0100 Subject: [PATCH 08/16] Add `:ref:` targets to `recwarn.rst`. --- AUTHORS | 1 + CHANGELOG.rst | 5 +++++ doc/en/recwarn.rst | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/AUTHORS b/AUTHORS index e966139bec3..d8fb8f70303 100644 --- a/AUTHORS +++ b/AUTHORS @@ -83,6 +83,7 @@ Kevin Cox Lee Kamentsky Lev Maximov Lukas Bednar +Luke Murphy Maciek Fijalkowski Maho Marc Schlaich diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 40797c30c6e..8fb7b158922 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,6 +3,9 @@ * Add hint to error message hinting possible missing __init__.py (`#478`_). Thanks `@DuncanBetts`_. +* Provide ``:ref:`` targets for ``recwarn.rst`` so we can use intersphinx referencing. + Thanks to `@dupuy`_ for the report and `@lwm`_ for the PR. + * An error message is now displayed if ``--confcutdir`` is not a valid directory, avoiding subtle bugs (`#2078`_). Thanks `@nicoddemus`_ for the PR. @@ -19,6 +22,8 @@ * +.. _@dupuy: https://bitbucket.org/dupuy/ +.. _@lwm: https://github.com/lwm .. _@adler-j: https://github.com/adler-j .. _@DuncanBetts: https://github.com/DuncanBetts .. _@nedbat: https://github.com/nedbat diff --git a/doc/en/recwarn.rst b/doc/en/recwarn.rst index 7350060169a..7bb193c99ef 100644 --- a/doc/en/recwarn.rst +++ b/doc/en/recwarn.rst @@ -1,8 +1,12 @@ +.. _`asserting warnings`: + .. _assertwarnings: Asserting Warnings ===================================================== +.. _`asserting warnings with the warns function`: + .. _warns: Asserting warnings with the warns function @@ -46,6 +50,8 @@ Alternatively, you can examine raised warnings in detail using the ``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated differently; see :ref:`ensuring_function_triggers`. +.. _`recording warnings`: + .. _recwarn: Recording warnings @@ -96,6 +102,8 @@ class of the warning. The ``message`` is the warning itself; calling ``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated differently; see :ref:`ensuring_function_triggers`. +.. _`ensuring a function triggers a deprecation warning`: + .. _ensuring_function_triggers: Ensuring a function triggers a deprecation warning From 6c5475660afadd66a8ab46c415e45e2839d3d581 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sat, 26 Nov 2016 18:47:26 +0100 Subject: [PATCH 09/16] Add test case for #595. This new test proves that reports do not capture stdout by default when skipped. --- testing/test_junitxml.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 85e49e451ec..443b8111beb 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -249,6 +249,18 @@ def test_skip(): snode = tnode.find_first_by_tag("skipped") snode.assert_attr(type="pytest.skip", message="hello25", ) + def test_mark_skip_doesnt_capture_output(self, testdir): + testdir.makepyfile(""" + import pytest + @pytest.mark.skip(reason="foo") + def test_skip(): + print("bar!") + """) + result, dom = runandparse(testdir) + assert result.ret == 0 + node_xml = dom.find_first_by_tag("testsuite").toxml() + assert "bar!" not in node_xml + def test_classname_instance(self, testdir): testdir.makepyfile(""" class TestClass: From 0aa891543d4b3961e600f2f153f57bdff4f3963f Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sat, 26 Nov 2016 18:57:51 +0100 Subject: [PATCH 10/16] Add documentation building note. --- CONTRIBUTING.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 19b31c7f447..71dc04d913d 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -79,6 +79,16 @@ Pytest could always use more documentation. What exactly is needed? You can also edit documentation files directly in the GitHub web interface, without using a local copy. This can be convenient for small fixes. +.. note:: + Build the documentation locally with the following command: + + .. code:: bash + + $ tox -e docs + + The built documentation should be available in the ``doc/en/_build/``. + + Where 'en' refers to the documentation language. .. _submitplugin: From 5566b3ccb6949623137e693da570176fa56a8cf0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 27 Nov 2016 03:26:35 -0200 Subject: [PATCH 11/16] Remove setuptools pin now that upstream has been fixed Related to pypa/setuptools#861 --- tox.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/tox.ini b/tox.ini index f0c8e93d4f5..f3494e8be72 100644 --- a/tox.ini +++ b/tox.ini @@ -119,8 +119,6 @@ usedevelop=True skipsdist=True deps= PyYAML - # pinning setuptools because of AppVeyor failures, see pypa/setuptools#861 - setuptools<29.0.0 commands= pytest -rfsxX doc/en pytest --doctest-modules {toxinidir}/_pytest From b38fad4b82123b392409fe78be01db2f39c7985b Mon Sep 17 00:00:00 2001 From: nmundar Date: Sat, 26 Nov 2016 12:22:58 +0100 Subject: [PATCH 12/16] Add compatproperty deprecation warning. --- _pytest/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/_pytest/main.py b/_pytest/main.py index dd0775501a1..33d7ef432ce 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -190,7 +190,9 @@ def __getattr__(self, name): def compatproperty(name): def fget(self): - # deprecated - use pytest.name + import warnings + warnings.warn("compatproperty is deprecated. Use pytest.name", + PendingDeprecationWarning, stacklevel=2) return getattr(pytest, name) return property(fget) From 0e6ad8e59f7ee25860c2cf4626d26f2dabd37ef5 Mon Sep 17 00:00:00 2001 From: nmundar Date: Sat, 26 Nov 2016 12:36:32 +0100 Subject: [PATCH 13/16] update CHANGELOG and AUTHORS --- AUTHORS | 1 + CHANGELOG.rst | 3 +++ 2 files changed, 4 insertions(+) diff --git a/AUTHORS b/AUTHORS index d8fb8f70303..8c7cb19cee4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -104,6 +104,7 @@ Michael Droettboom Michael Seifert Mike Lundy Ned Batchelder +Neven Mundar Nicolas Delaby Oleg Pidsadnyi Oliver Bestwalter diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8fb7b158922..1820e083aca 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,9 @@ * Provide ``:ref:`` targets for ``recwarn.rst`` so we can use intersphinx referencing. Thanks to `@dupuy`_ for the report and `@lwm`_ for the PR. +* Using ``pytest.main.compatproperty`` is now issuing deprecation warning. + Thanks `@nmundar` for the PR. + * An error message is now displayed if ``--confcutdir`` is not a valid directory, avoiding subtle bugs (`#2078`_). Thanks `@nicoddemus`_ for the PR. From 0a30f072e65da60f284af399e55c2ec897afb9cd Mon Sep 17 00:00:00 2001 From: nmundar Date: Sat, 26 Nov 2016 21:37:43 +0100 Subject: [PATCH 14/16] Show name argment in compatproperty deprecation message --- _pytest/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/main.py b/_pytest/main.py index 33d7ef432ce..2b5b1287528 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -191,7 +191,7 @@ def __getattr__(self, name): def compatproperty(name): def fget(self): import warnings - warnings.warn("compatproperty is deprecated. Use pytest.name", + warnings.warn("This usage is deprecated, please use pytest.{0} instead".format(name), PendingDeprecationWarning, stacklevel=2) return getattr(pytest, name) From 2d7197926a8a2bb1cb8aebbe1fcb86e99837cad8 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 27 Nov 2016 14:19:29 -0200 Subject: [PATCH 15/16] Improve CHANGELOG entry for #2034 --- CHANGELOG.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1820e083aca..77b67ddbb4e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,13 +1,14 @@ 3.0.5.dev0 ========== -* Add hint to error message hinting possible missing __init__.py (`#478`_). Thanks `@DuncanBetts`_. +* Add hint to error message hinting possible missing ``__init__.py`` (`#478`_). Thanks `@DuncanBetts`_. * Provide ``:ref:`` targets for ``recwarn.rst`` so we can use intersphinx referencing. Thanks to `@dupuy`_ for the report and `@lwm`_ for the PR. -* Using ``pytest.main.compatproperty`` is now issuing deprecation warning. - Thanks `@nmundar` for the PR. +* Using ``item.Function``, ``item.Module``, etc., is now issuing deprecation warnings, prefer + ``pytest.Function``, ``pytest.Module``, etc., instead (`#2034`_). + Thanks `@nmundar`_ for the PR. * An error message is now displayed if ``--confcutdir`` is not a valid directory, avoiding subtle bugs (`#2078`_). @@ -30,8 +31,10 @@ .. _@adler-j: https://github.com/adler-j .. _@DuncanBetts: https://github.com/DuncanBetts .. _@nedbat: https://github.com/nedbat +.. _@nmundar: https://github.com/nmundar .. _#478: https://github.com/pytest-dev/pytest/issues/478 +.. _#2034: https://github.com/pytest-dev/pytest/issues/2034 .. _#2038: https://github.com/pytest-dev/pytest/issues/2038 .. _#2078: https://github.com/pytest-dev/pytest/issues/2078 .. _#2082: https://github.com/pytest-dev/pytest/issues/2082 From 788e394c935ef9f24ce1ef9035dbc570c17fe0ed Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 27 Nov 2016 14:45:52 -0200 Subject: [PATCH 16/16] Use "inc" instead of "func" in the snipped on README and doc index "inc" reads better, also fixed the line separators so they have the same size --- README.rst | 16 ++++++++-------- doc/en/index.rst | 26 ++++++++++++-------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index 5b2d329e053..d5650af6552 100644 --- a/README.rst +++ b/README.rst @@ -24,31 +24,31 @@ An example of a simple test: .. code-block:: python # content of test_sample.py - def func(x): + def inc(x): return x + 1 def test_answer(): - assert func(3) == 5 + assert inc(3) == 5 To execute it:: $ pytest - ======= test session starts ======== + ============================= test session starts ============================= collected 1 items test_sample.py F - ======= FAILURES ======== - _______ test_answer ________ + ================================== FAILURES =================================== + _________________________________ test_answer _________________________________ def test_answer(): - > assert func(3) == 5 + > assert inc(3) == 5 E assert 4 == 5 - E + where 4 = func(3) + E + where 4 = inc(3) test_sample.py:5: AssertionError - ======= 1 failed in 0.12 seconds ======== + ========================== 1 failed in 0.04 seconds =========================== Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. See `getting-started `_ for more examples. diff --git a/doc/en/index.rst b/doc/en/index.rst index aadabf2227b..67b13d3e3f3 100644 --- a/doc/en/index.rst +++ b/doc/en/index.rst @@ -14,33 +14,31 @@ An example of a simple test: .. code-block:: python # content of test_sample.py - def func(x): + def inc(x): return x + 1 def test_answer(): - assert func(3) == 5 + assert inc(3) == 5 To execute it:: $ pytest - ======= test session starts ======== - platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0 - rootdir: $REGENDOC_TMPDIR, inifile: + ============================= test session starts ============================= collected 1 items - + test_sample.py F - - ======= FAILURES ======== - _______ test_answer ________ - + + ================================== FAILURES =================================== + _________________________________ test_answer _________________________________ + def test_answer(): - > assert func(3) == 5 + > assert inc(3) == 5 E assert 4 == 5 - E + where 4 = func(3) - + E + where 4 = inc(3) + test_sample.py:5: AssertionError - ======= 1 failed in 0.12 seconds ======== + ========================== 1 failed in 0.04 seconds =========================== Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. See :ref:`Getting Started ` for more examples.