From 8617764a59aa64e02f3c5259ef1decb51354371e Mon Sep 17 00:00:00 2001 From: RedBeardCode Date: Sat, 25 Jun 2016 11:27:10 +0200 Subject: [PATCH] Remove deprecated cmd options Fixes #1657 --- CHANGELOG.rst | 14 ++++- _pytest/assertion/__init__.py | 11 ---- _pytest/genscript.py | 40 -------------- _pytest/standalonetemplate.py | 89 ------------------------------- _pytest/terminal.py | 14 ----- doc/en/assert.rst | 3 ++ doc/en/getting-started.rst | 7 +-- doc/en/goodpractices.rst | 33 ------------ doc/en/plugins.rst | 1 - doc/en/test/plugin/genscript.rst | 28 ---------- doc/en/test/plugin/helpconfig.rst | 2 - doc/en/test/plugin/links.rst | 2 - doc/en/test/plugin/terminal.rst | 2 - testing/test_assertion.py | 14 ++--- testing/test_config.py | 2 +- testing/test_genscript.py | 51 ------------------ testing/test_skipping.py | 6 +-- testing/test_terminal.py | 9 ---- 18 files changed, 24 insertions(+), 304 deletions(-) delete mode 100755 _pytest/standalonetemplate.py delete mode 100644 doc/en/test/plugin/genscript.rst delete mode 100644 testing/test_genscript.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 427be0910dc..4287574e1d1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -38,7 +38,18 @@ * -* +**Incompatible changes** + +* Removing the following deprecated commandline options + + * genscript + * no-assert + * nomagic + * report + + Thanks to `@RedBeardCode`_ for the PR(`#1664`_) + + .. _#1580: https://github.com/pytest-dev/pytest/pull/1580 .. _#1605: https://github.com/pytest-dev/pytest/issues/1605 @@ -47,6 +58,7 @@ .. _#1553: https://github.com/pytest-dev/pytest/issues/1553 .. _#1626: https://github.com/pytest-dev/pytest/pull/1626 .. _#1503: https://github.com/pytest-dev/pytest/issues/1503 +.. _#1664: https://github.com/pytest-dev/pytest/pull/1664 .. _@graingert: https://github.com/graingert .. _@taschini: https://github.com/taschini diff --git a/_pytest/assertion/__init__.py b/_pytest/assertion/__init__.py index 6921deb2a60..394e7ab14f6 100644 --- a/_pytest/assertion/__init__.py +++ b/_pytest/assertion/__init__.py @@ -23,15 +23,6 @@ def pytest_addoption(parser): 'rewrite' (the default) rewrites assert statements in test modules on import to provide assert expression information. """) - group.addoption('--no-assert', - action="store_true", - default=False, - dest="noassert", - help="DEPRECATED equivalent to --assert=plain") - group.addoption('--nomagic', '--no-magic', - action="store_true", - default=False, - help="DEPRECATED equivalent to --assert=plain") class AssertionState: @@ -44,8 +35,6 @@ def __init__(self, config, mode): def pytest_configure(config): mode = config.getvalue("assertmode") - if config.getvalue("noassert") or config.getvalue("nomagic"): - mode = "plain" if mode == "rewrite": try: import ast # noqa diff --git a/_pytest/genscript.py b/_pytest/genscript.py index d2962d8fc82..80bb75f541e 100755 --- a/_pytest/genscript.py +++ b/_pytest/genscript.py @@ -52,46 +52,6 @@ def compress_packages(names): mapping.update(pkg_to_mapping(name)) return compress_mapping(mapping) -def generate_script(entry, packages): - data = compress_packages(packages) - tmpl = py.path.local(__file__).dirpath().join('standalonetemplate.py') - exe = tmpl.read() - exe = exe.replace('@SOURCES@', data) - exe = exe.replace('@ENTRY@', entry) - return exe - - -def pytest_addoption(parser): - group = parser.getgroup("debugconfig") - group.addoption("--genscript", action="store", default=None, - dest="genscript", metavar="path", - help="create standalone pytest script at given target path.") - -def pytest_cmdline_main(config): - import _pytest.config - genscript = config.getvalue("genscript") - if genscript: - tw = _pytest.config.create_terminal_writer(config) - tw.line("WARNING: usage of genscript is deprecated.", - red=True) - deps = ['py', '_pytest', 'pytest'] # pluggy is vendored - if sys.version_info < (2,7): - deps.append("argparse") - tw.line("generated script will run on python2.6-python3.3++") - else: - tw.line("WARNING: generated script will not run on python2.6 " - "due to 'argparse' dependency. Use python2.6 " - "to generate a python2.6 compatible script", red=True) - script = generate_script( - 'import pytest; raise SystemExit(pytest.cmdline.main())', - deps, - ) - genscript = py.path.local(genscript) - genscript.write(script) - tw.line("generated pytest standalone script: %s" % genscript, - bold=True) - return 0 - def pytest_namespace(): return {'freeze_includes': freeze_includes} diff --git a/_pytest/standalonetemplate.py b/_pytest/standalonetemplate.py deleted file mode 100755 index 484d5d1b25f..00000000000 --- a/_pytest/standalonetemplate.py +++ /dev/null @@ -1,89 +0,0 @@ -#! /usr/bin/env python - -# Hi There! -# You may be wondering what this giant blob of binary data here is, you might -# even be worried that we're up to something nefarious (good for you for being -# paranoid!). This is a base64 encoding of a zip file, this zip file contains -# a fully functional basic pytest script. -# -# Pytest is a thing that tests packages, pytest itself is a package that some- -# one might want to install, especially if they're looking to run tests inside -# some package they want to install. Pytest has a lot of code to collect and -# execute tests, and other such sort of "tribal knowledge" that has been en- -# coded in its code base. Because of this we basically include a basic copy -# of pytest inside this blob. We do this because it let's you as a maintainer -# or application developer who wants people who don't deal with python much to -# easily run tests without installing the complete pytest package. -# -# If you're wondering how this is created: you can create it yourself if you -# have a complete pytest installation by using this command on the command- -# line: ``py.test --genscript=runtests.py``. - -sources = """ -@SOURCES@""" - -import sys -import base64 -import zlib - -class DictImporter(object): - def __init__(self, sources): - self.sources = sources - - def find_module(self, fullname, path=None): - if fullname == "argparse" and sys.version_info >= (2,7): - # we were generated with = (3, 0): - exec("def do_exec(co, loc): exec(co, loc)\n") - import pickle - sources = sources.encode("ascii") # ensure bytes - sources = pickle.loads(zlib.decompress(base64.decodebytes(sources))) - else: - import cPickle as pickle - exec("def do_exec(co, loc): exec co in loc\n") - sources = pickle.loads(zlib.decompress(base64.decodestring(sources))) - - importer = DictImporter(sources) - sys.meta_path.insert(0, importer) - entry = "@ENTRY@" - do_exec(entry, locals()) # noqa diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 825f553ef2c..b88a19e139e 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -27,9 +27,6 @@ def pytest_addoption(parser): group._addoption('-l', '--showlocals', action="store_true", dest="showlocals", default=False, help="show locals in tracebacks (disabled by default).") - group._addoption('--report', - action="store", dest="report", default=None, metavar="opts", - help="(deprecated, use -r)") group._addoption('--tb', metavar="style", action="store", dest="tbstyle", default='auto', choices=['auto', 'long', 'short', 'no', 'line', 'native'], @@ -54,17 +51,6 @@ def mywriter(tags, args): def getreportopt(config): reportopts = "" - optvalue = config.option.report - if optvalue: - py.builtin.print_("DEPRECATED: use -r instead of --report option.", - file=sys.stderr) - if optvalue: - for setting in optvalue.split(","): - setting = setting.strip() - if setting == "skipped": - reportopts += "s" - elif setting == "xfailed": - reportopts += "x" reportchars = config.option.reportchars if reportchars: for char in reportchars: diff --git a/doc/en/assert.rst b/doc/en/assert.rst index aff08f0f6e7..04b04f75f03 100644 --- a/doc/en/assert.rst +++ b/doc/en/assert.rst @@ -287,3 +287,6 @@ For further information, Benjamin Peterson wrote up `Behind the scenes of pytest .. versionchanged:: 2.1 Introduce the ``--assert`` option. Deprecate ``--no-assert`` and ``--nomagic``. + +.. versionchanged:: 3.0 + Removes the ``--no-assert`` and``--nomagic`` options. diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index 0372f7f3b02..64b8bdb3833 100644 --- a/doc/en/getting-started.rst +++ b/doc/en/getting-started.rst @@ -193,7 +193,7 @@ Where to go next Here are a few suggestions where to go next: * :ref:`cmdline` for command line invocation examples -* :ref:`good practices ` for virtualenv, test layout, genscript support +* :ref:`good practices ` for virtualenv, test layout * :ref:`fixtures` for providing a functional baseline to your tests * :ref:`apiref` for documentation and examples on using ``pytest`` * :ref:`plugins` managing and writing plugins @@ -227,11 +227,6 @@ py.test not found on Windows despite installation? .. _`Jython does not create command line launchers`: http://bugs.jython.org/issue1491 -- **Jython2.5.1 on Windows XP**: `Jython does not create command line launchers`_ - so ``py.test`` will not work correctly. You may install py.test on - CPython and type ``py.test --genscript=mytest`` and then use - ``jython mytest`` to run your tests with Jython using ``pytest``. - :ref:`examples` for more complex examples .. include:: links.inc diff --git a/doc/en/goodpractices.rst b/doc/en/goodpractices.rst index 89396b57ed8..8c3e47ac8b8 100644 --- a/doc/en/goodpractices.rst +++ b/doc/en/goodpractices.rst @@ -243,38 +243,5 @@ using the ``--pytest-args`` or ``-a`` command-line option. For example:: is equivalent to running ``py.test --durations=5``. -.. _standalone: -.. _`genscript method`: - -(deprecated) Create a pytest standalone script ------------------------------------------------ - -.. deprecated:: 2.8 - -.. note:: - - ``genscript`` has been deprecated because: - - * It cannot support plugins, rendering its usefulness extremely limited; - * Tooling has become much better since ``genscript`` was introduced; - * It is possible to build a zipped ``pytest`` application without the - shortcomings above. - - There's no planned version in which this command will be removed - at the moment of this writing, but its use is discouraged for new - applications. - -If you are a maintainer or application developer and want people -who don't deal with python much to easily run tests you may generate -a standalone ``pytest`` script:: - - py.test --genscript=runtests.py - -This generates a ``runtests.py`` script which is a fully functional basic -``pytest`` script, running unchanged under Python2 and Python3. -You can tell people to download the script and then e.g. run it like this:: - - python runtests.py - .. include:: links.inc diff --git a/doc/en/plugins.rst b/doc/en/plugins.rst index 3db7f0f5940..ada0c132181 100644 --- a/doc/en/plugins.rst +++ b/doc/en/plugins.rst @@ -138,7 +138,6 @@ in the `pytest repository `_. _pytest.capture _pytest.config _pytest.doctest - _pytest.genscript _pytest.helpconfig _pytest.junitxml _pytest.mark diff --git a/doc/en/test/plugin/genscript.rst b/doc/en/test/plugin/genscript.rst deleted file mode 100644 index ee80f233fa0..00000000000 --- a/doc/en/test/plugin/genscript.rst +++ /dev/null @@ -1,28 +0,0 @@ - -(deprecated) generate standalone test script to be distributed along with an application. -============================================================================ - - -.. contents:: - :local: - - - -command line options --------------------- - - -``--genscript=path`` - create standalone ``pytest`` script at given target path. - -Start improving this plugin in 30 seconds -========================================= - - -1. Download `pytest_genscript.py`_ plugin source code -2. put it somewhere as ``pytest_genscript.py`` into your import path -3. a subsequent ``pytest`` run will use your local version - -Checkout customize_, other plugins_ or `get in contact`_. - -.. include:: links.txt diff --git a/doc/en/test/plugin/helpconfig.rst b/doc/en/test/plugin/helpconfig.rst index 00399b6901c..326b75c4552 100644 --- a/doc/en/test/plugin/helpconfig.rst +++ b/doc/en/test/plugin/helpconfig.rst @@ -18,8 +18,6 @@ command line options early-load given plugin (multi-allowed). ``--trace-config`` trace considerations of conftest.py files. -``--nomagic`` - don't reinterpret asserts, no traceback cutting. ``--debug`` generate and show internal debugging information. ``--help-config`` diff --git a/doc/en/test/plugin/links.rst b/doc/en/test/plugin/links.rst index aa965e73049..6dec2b4848a 100644 --- a/doc/en/test/plugin/links.rst +++ b/doc/en/test/plugin/links.rst @@ -2,10 +2,8 @@ .. _`pytest_recwarn.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_recwarn.py .. _`unittest`: unittest.html .. _`pytest_monkeypatch.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_monkeypatch.py -.. _`pytest_genscript.py`: http://bitbucket.org/hpk42/py-trunk/raw/1.3.4/py/_plugin/pytest_genscript.py .. _`pastebin`: pastebin.html .. _`skipping`: skipping.html -.. _`genscript`: genscript.html .. _`plugins`: index.html .. _`mark`: mark.html .. _`tmpdir`: tmpdir.html diff --git a/doc/en/test/plugin/terminal.rst b/doc/en/test/plugin/terminal.rst index 0c079641515..e07d4f72183 100644 --- a/doc/en/test/plugin/terminal.rst +++ b/doc/en/test/plugin/terminal.rst @@ -18,8 +18,6 @@ command line options show extra test summary info as specified by chars (f)ailed, (s)skipped, (x)failed, (X)passed. ``-l, --showlocals`` show locals in tracebacks (disabled by default). -``--report=opts`` - (deprecated, use -r) ``--tb=style`` traceback print mode (long/short/line/no). ``--full-trace`` diff --git a/testing/test_assertion.py b/testing/test_assertion.py index dfa1b942034..15d49433290 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -474,16 +474,8 @@ def test_hello(): """) result = testdir.runpytest() assert "3 == 4" in result.stdout.str() - off_options = (("--no-assert",), - ("--nomagic",), - ("--no-assert", "--nomagic"), - ("--assert=plain",), - ("--assert=plain", "--no-assert"), - ("--assert=plain", "--nomagic"), - ("--assert=plain", "--no-assert", "--nomagic")) - for opt in off_options: - result = testdir.runpytest_subprocess(*opt) - assert "3 == 4" not in result.stdout.str() + result = testdir.runpytest_subprocess("--assert=plain") + assert "3 == 4" not in result.stdout.str() def test_old_assert_mode(testdir): testdir.makepyfile(""" @@ -559,7 +551,7 @@ def test_warn_missing(testdir): result.stderr.fnmatch_lines([ "*WARNING*assert statements are not executed*", ]) - result = testdir.run(sys.executable, "-OO", "-m", "pytest", "--no-assert") + result = testdir.run(sys.executable, "-OO", "-m", "pytest") result.stderr.fnmatch_lines([ "*WARNING*assert statements are not executed*", ]) diff --git a/testing/test_config.py b/testing/test_config.py index fe06540173e..48a2229640c 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -365,7 +365,7 @@ def test_f2(): assert 0 """) for opts in ([], ['-l'], ['-s'], ['--tb=no'], ['--tb=short'], - ['--tb=long'], ['--fulltrace'], ['--nomagic'], + ['--tb=long'], ['--fulltrace'], ['--traceconfig'], ['-v'], ['-v', '-v']): runfiletest(opts + [path]) diff --git a/testing/test_genscript.py b/testing/test_genscript.py deleted file mode 100644 index 1d51c6e8d78..00000000000 --- a/testing/test_genscript.py +++ /dev/null @@ -1,51 +0,0 @@ -import pytest -import sys - - -@pytest.fixture(scope="module") -def standalone(request): - return Standalone(request) - -class Standalone: - def __init__(self, request): - self.testdir = request.getfixturevalue("testdir") - script = "mypytest" - result = self.testdir.runpytest("--genscript=%s" % script) - assert result.ret == 0 - self.script = self.testdir.tmpdir.join(script) - assert self.script.check() - - def run(self, anypython, testdir, *args): - return testdir._run(anypython, self.script, *args) - -def test_gen(testdir, anypython, standalone): - if sys.version_info >= (2,7): - result = testdir._run(anypython, "-c", - "import sys;print (sys.version_info >=(2,7))") - assert result.ret == 0 - if result.stdout.str() == "False": - pytest.skip("genscript called from python2.7 cannot work " - "earlier python versions") - result = standalone.run(anypython, testdir, '--version') - if result.ret == 2: - result.stderr.fnmatch_lines(["*ERROR: setuptools not installed*"]) - elif result.ret == 0: - result.stderr.fnmatch_lines([ - "*imported from*mypytest*" - ]) - p = testdir.makepyfile("def test_func(): assert 0") - result = standalone.run(anypython, testdir, p) - assert result.ret != 0 - else: - pytest.fail("Unexpected return code") - - -def test_freeze_includes(): - """ - Smoke test for freeze_includes(), to ensure that it works across all - supported python versions. - """ - includes = pytest.freeze_includes() - assert len(includes) > 1 - assert '_pytest.genscript' in includes - diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 2bfb6a8dc58..a4f097c9958 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -209,7 +209,7 @@ def test_this_true(): def test_this_false(): assert 1 """) - result = testdir.runpytest(p, '--report=xfailed', ) + result = testdir.runpytest(p, '-rx', ) result.stdout.fnmatch_lines([ "*test_one*test_this*", "*NOTRUN*noway", @@ -227,7 +227,7 @@ def test_this(): def setup_module(mod): raise ValueError(42) """) - result = testdir.runpytest(p, '--report=xfailed', ) + result = testdir.runpytest(p, '-rx', ) result.stdout.fnmatch_lines([ "*test_one*test_this*", "*NOTRUN*hello", @@ -692,7 +692,7 @@ def doskip(): pytest.skip('test') """ ) - result = testdir.runpytest('--report=skipped') + result = testdir.runpytest('-rs') result.stdout.fnmatch_lines([ "*SKIP*3*conftest.py:3: test", ]) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index be5749c96d2..cd597d1d702 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -591,16 +591,7 @@ def test_getreportopt(): class config: class option: reportchars = "" - config.option.report = "xfailed" - assert getreportopt(config) == "x" - config.option.report = "xfailed,skipped" - assert getreportopt(config) == "xs" - - config.option.report = "skipped,xfailed" - assert getreportopt(config) == "sx" - - config.option.report = "skipped" config.option.reportchars = "sf" assert getreportopt(config) == "sf"