From 65f5383106d4fbe7680bf154673198d68f590f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Fri, 1 Dec 2017 13:21:06 +0100 Subject: [PATCH 01/11] fix comment & docstring typos, line wrapping & wording --- _pytest/pytester.py | 319 ++++++++++++++++++++++---------------------- 1 file changed, 159 insertions(+), 160 deletions(-) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index f2dd5994f1b..70436b24690 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -1,4 +1,4 @@ -""" (disabled by default) support for testing pytest and pytest plugins. """ +"""(disabled by default) support for testing pytest and pytest plugins.""" from __future__ import absolute_import, division, print_function import codecs @@ -76,8 +76,8 @@ def matching_platform(self): try: py.process.cmdexec("lsof -v") except (py.process.cmdexec.Error, UnicodeDecodeError): - # cmdexec may raise UnicodeDecodeError on Windows systems - # with locale other than english: + # cmdexec may raise UnicodeDecodeError on Windows systems with + # locale other than English: # https://bitbucket.org/pytest-dev/py/issues/66 return False else: @@ -132,7 +132,7 @@ def getexecutable(name, cache={}): if "2.5.2" in err: executable = None # http://bugs.jython.org/issue1790 elif popen.returncode != 0: - # Handle pyenv's 127. + # handle pyenv's 127 executable = None cache[name] = executable return executable @@ -157,9 +157,10 @@ def anypython(request): @pytest.fixture def _pytest(request): - """ Return a helper which offers a gethookrecorder(hook) - method which returns a HookRecorder instance which helps - to make assertions about called hooks. + """Return a helper which offers a gethookrecorder(hook) method which + returns a HookRecorder instance which helps to make assertions about called + hooks. + """ return PytestArg(request) @@ -193,8 +194,8 @@ def __repr__(self): class HookRecorder: """Record all hooks called in a plugin manager. - This wraps all the hook calls in the plugin manager, recording - each call before propagating the normal calls. + This wraps all the hook calls in the plugin manager, recording each call + before propagating the normal calls. """ @@ -262,7 +263,7 @@ def getreports(self, def matchreport(self, inamepart="", names="pytest_runtest_logreport pytest_collectreport", when=None): - """ return a testreport whose dotted import path matches """ + """return a testreport whose dotted import path matches""" values = [] for rep in self.getreports(names=names): try: @@ -341,14 +342,14 @@ class RunResult: Attributes: - :ret: The return value. - :outlines: List of lines captured from stdout. - :errlines: List of lines captures from stderr. + :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 - reconstruct stdout or the commonly used - ``stdout.fnmatch_lines()`` method. - :stderrr: :py:class:`LineMatcher` of stderr. - :duration: Duration in seconds. + reconstruct stdout or the commonly used ``stdout.fnmatch_lines()`` + method + :stderrr: :py:class:`LineMatcher` of stderr + :duration: duration in seconds """ @@ -361,8 +362,10 @@ def __init__(self, ret, outlines, errlines, duration): self.duration = duration def parseoutcomes(self): - """ Return a dictionary of outcomestring->num from parsing - the terminal output that the test process produced.""" + """Return a dictionary of outcomestring->num from parsing the terminal + output that the test process produced. + + """ for line in reversed(self.outlines): if 'seconds' in line: outcomes = rex_outcome.findall(line) @@ -374,8 +377,10 @@ def parseoutcomes(self): raise ValueError("Pytest terminal report not found") def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0): - """ assert that the specified outcomes appear with the respective - numbers (0 means it didn't occur) in the text output from a test run.""" + """Assert that the specified outcomes appear with the respective + numbers (0 means it didn't occur) in the text output from a test run. + + """ d = self.parseoutcomes() obtained = { 'passed': d.get('passed', 0), @@ -389,21 +394,18 @@ def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0): class Testdir: """Temporary test directory with tools to test/run pytest itself. - This is based on the ``tmpdir`` fixture but provides a number of - methods which aid with testing pytest itself. Unless - :py:meth:`chdir` is used all methods will use :py:attr:`tmpdir` as - current working directory. + This is based on the ``tmpdir`` fixture but provides a number of methods + which aid with testing pytest itself. Unless :py:meth:`chdir` is used all + methods will use :py:attr:`tmpdir` as their current working directory. Attributes: - :tmpdir: The :py:class:`py.path.local` instance of the temporary - directory. + :tmpdir: The :py:class:`py.path.local` instance of the temporary directory. :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 depend on the method which uses them so refer to them - for details. + :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. """ @@ -429,10 +431,9 @@ def __repr__(self): def finalize(self): """Clean up global state artifacts. - Some methods modify the global interpreter state and this - tries to clean this up. It does not remove the temporary - directory however so it can be looked at after the test run - has finished. + Some methods modify the global interpreter state and this tries to + clean this up. It does not remove the temporary directory however so + it can be looked at after the test run has finished. """ sys.path[:], sys.meta_path[:] = self._savesyspath @@ -495,17 +496,15 @@ def to_text(s): def makefile(self, ext, *args, **kwargs): """Create a new file in the testdir. - ext: The extension the file should use, including the dot. - E.g. ".py". + ext: The extension the file should use, including the dot, e.g. `.py`. - args: All args will be treated as strings and joined using - newlines. The result will be written as contents to the - file. The name of the file will be based on the test - function requesting this fixture. + args: All args will be treated as strings and joined using newlines. + The result will be written as contents to the file. The name of the + file will be based on the test function requesting this fixture. E.g. "testdir.makefile('.txt', 'line1', 'line2')" - kwargs: Each keyword is the name of a file, while the value of - it will be written as contents of the file. + kwargs: Each keyword is the name of a file, while the value of it will + be written as contents of the file. E.g. "testdir.makefile('.ini', pytest='[pytest]\naddopts=-rs\n')" """ @@ -535,14 +534,16 @@ def maketxtfile(self, *args, **kwargs): def syspathinsert(self, path=None): """Prepend a directory to sys.path, defaults to :py:attr:`tmpdir`. - This is undone automatically after the test. + This is undone automatically when this object dies at the end of each + test. + """ if path is None: path = self.tmpdir sys.path.insert(0, str(path)) - # a call to syspathinsert() usually means that the caller - # wants to import some dynamically created files. - # with python3 we thus invalidate import caches. + # a call to syspathinsert() usually means that the caller wants to + # import some dynamically created files, thus with python3 we + # invalidate its import caches self._possibly_invalidate_import_caches() def _possibly_invalidate_import_caches(self): @@ -562,8 +563,8 @@ def mkdir(self, name): def mkpydir(self, name): """Create a new python package. - This creates a (sub)directory with an empty ``__init__.py`` - file so that is recognised as a python package. + This creates a (sub)directory with an empty ``__init__.py`` file so it + gets recognised as a python package. """ p = self.mkdir(name) @@ -576,10 +577,10 @@ def getnode(self, config, arg): """Return the collection node of a file. :param config: :py:class:`_pytest.config.Config` instance, see - :py:meth:`parseconfig` and :py:meth:`parseconfigure` to - create the configuration. + :py:meth:`parseconfig` and :py:meth:`parseconfigure` to create the + configuration - :param arg: A :py:class:`py.path.local` instance of the file. + :param arg: a :py:class:`py.path.local` instance of the file """ session = Session(config) @@ -593,11 +594,10 @@ def getnode(self, config, arg): def getpathnode(self, path): """Return the collection node of a file. - This is like :py:meth:`getnode` but uses - :py:meth:`parseconfigure` to create the (configured) pytest - Config instance. + This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to + create the (configured) pytest Config instance. - :param path: A :py:class:`py.path.local` instance of the file. + :param path: a :py:class:`py.path.local` instance of the file """ config = self.parseconfigure(path) @@ -611,8 +611,8 @@ def getpathnode(self, path): def genitems(self, colitems): """Generate all test items from a collection node. - This recurses into the collection node and returns a list of - all the test items contained within. + This recurses into the collection node and returns a list of all the + test items contained within. """ session = colitems[0].session @@ -624,10 +624,10 @@ def genitems(self, colitems): def runitem(self, source): """Run the "test_func" Item. - The calling test instance (the class which contains the test - method) must provide a ``.getrunner()`` method which should - return a runner which can run the test protocol for a single - item, like e.g. :py:func:`_pytest.runner.runtestprotocol`. + The calling test instance (class containing the test method) must + provide a ``.getrunner()`` method which should return a runner which + can run the test protocol for a single item, e.g. + :py:func:`_pytest.runner.runtestprotocol`. """ # used from runner functional tests @@ -641,14 +641,14 @@ def inline_runsource(self, source, *cmdlineargs): """Run a test module in process using ``pytest.main()``. This run writes "source" into a temporary file and runs - ``pytest.main()`` on it, returning a :py:class:`HookRecorder` - instance for the result. + ``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance + for the result. - :param source: The source code of the test module. + :param source: the source code of the test module - :param cmdlineargs: Any extra command line arguments to use. + :param cmdlineargs: any extra command line arguments to use - :return: :py:class:`HookRecorder` instance of the result. + :return: :py:class:`HookRecorder` instance of the result """ p = self.makepyfile(source) @@ -658,13 +658,9 @@ def inline_runsource(self, source, *cmdlineargs): def inline_genitems(self, *args): """Run ``pytest.main(['--collectonly'])`` in-process. - Returns a tuple of the collected items and a - :py:class:`HookRecorder` instance. - - This runs the :py:func:`pytest.main` function to run all of - pytest inside the test process itself like - :py:meth:`inline_run`. However the return value is a tuple of - the collection items and a :py:class:`HookRecorder` instance. + Runs the :py:func:`pytest.main` function to run all of pytest inside + the test process itself like :py:meth:`inline_run`, but returns a + tuple of the collected items and a :py:class:`HookRecorder` instance. """ rec = self.inline_run("--collect-only", *args) @@ -674,24 +670,24 @@ def inline_genitems(self, *args): def inline_run(self, *args, **kwargs): """Run ``pytest.main()`` in-process, returning a HookRecorder. - This runs the :py:func:`pytest.main` function to run all of - pytest inside the test process itself. This means it can - return a :py:class:`HookRecorder` instance which gives more - detailed results from then run then can be done by matching - stdout/stderr from :py:meth:`runpytest`. + Runs the :py:func:`pytest.main` function to run all of pytest inside + the test process itself. This means it can return a + :py:class:`HookRecorder` instance which gives more detailed results + from that run than can be done by matching stdout/stderr from + :py:meth:`runpytest`. - :param args: Any command line arguments to pass to - :py:func:`pytest.main`. + :param args: command line arguments to pass to :py:func:`pytest.main` - :param plugin: (keyword-only) Extra plugin instances the - ``pytest.main()`` instance should use. + :param plugin: (keyword-only) extra plugin instances the + ``pytest.main()`` instance should use + + :return: a :py:class:`HookRecorder` instance - :return: A :py:class:`HookRecorder` instance. """ - # When running py.test inline any plugins active in the main - # test process are already imported. So this disables the - # warning which will trigger to say they can no longer be - # rewritten, which is fine as they are already rewritten. + # When running py.test inline any plugins active in the main test + # process are already imported. So this disables the warning which + # will trigger to say they can no longer be rewritten, which is fine as + # they have already been rewritten. orig_warn = AssertionRewritingHook._warn_already_imported def revert(): @@ -717,8 +713,8 @@ class reprec: pass reprec.ret = ret - # typically we reraise keyboard interrupts from the child run - # because it's our user requesting interruption of the testing + # typically we reraise keyboard interrupts from the child run because + # it's our user requesting interruption of the testing if ret == 2 and not kwargs.get("no_reraise_ctrlc"): calls = reprec.getcalls("pytest_keyboard_interrupt") if calls and calls[-1].excinfo.type == KeyboardInterrupt: @@ -726,8 +722,10 @@ class reprec: return reprec def runpytest_inprocess(self, *args, **kwargs): - """ Return result of running pytest in-process, providing a similar - interface to what self.runpytest() provides. """ + """Return result of running pytest in-process, providing a similar + interface to what self.runpytest() provides. + + """ if kwargs.get("syspathinsert"): self.syspathinsert() now = time.time() @@ -759,7 +757,7 @@ class reprec: return res def runpytest(self, *args, **kwargs): - """ Run pytest inline or in a subprocess, depending on the command line + """Run pytest inline or in a subprocess, depending on the command line option "--runpytest" and return a :py:class:`RunResult`. """ @@ -780,13 +778,13 @@ def _ensure_basetemp(self, args): def parseconfig(self, *args): """Return a new pytest Config instance from given commandline args. - This invokes the pytest bootstrapping code in _pytest.config - to create a new :py:class:`_pytest.core.PluginManager` and - call the pytest_cmdline_parse hook to create new + This invokes the pytest bootstrapping code in _pytest.config to create + a new :py:class:`_pytest.core.PluginManager` and call the + pytest_cmdline_parse hook to create a new :py:class:`_pytest.config.Config` instance. - If :py:attr:`plugins` has been populated they should be plugin - modules which will be registered with the PluginManager. + If :py:attr:`plugins` has been populated they should be plugin modules + to be registered with the PluginManager. """ args = self._ensure_basetemp(args) @@ -802,9 +800,8 @@ def parseconfig(self, *args): def parseconfigure(self, *args): """Return a new pytest configured Config instance. - This returns a new :py:class:`_pytest.config.Config` instance - like :py:meth:`parseconfig`, but also calls the - pytest_configure hook. + This returns a new :py:class:`_pytest.config.Config` instance like + :py:meth:`parseconfig`, but also calls the pytest_configure hook. """ config = self.parseconfig(*args) @@ -815,14 +812,14 @@ def parseconfigure(self, *args): def getitem(self, source, funcname="test_func"): """Return the test item for a test function. - This writes the source to a python file and runs pytest's - collection on the resulting module, returning the test item - for the requested function name. + This writes the source to a python file and runs pytest's collection on + the resulting module, returning the test item for the requested + function name. - :param source: The module source. + :param source: the module source - :param funcname: The name of the test function for which the - Item must be returned. + :param funcname: the name of the test function for which to return a + test item """ items = self.getitems(source) @@ -835,9 +832,8 @@ def getitem(self, source, funcname="test_func"): def getitems(self, source): """Return all test items collected from the module. - This writes the source to a python file and runs pytest's - collection on the resulting module, returning all test items - contained within. + This writes the source to a python file and runs pytest's collection on + the resulting module, returning all test items contained within. """ modcol = self.getmodulecol(source) @@ -846,17 +842,17 @@ def getitems(self, source): def getmodulecol(self, source, configargs=(), withinit=False): """Return the module collection node for ``source``. - This writes ``source`` to a file using :py:meth:`makepyfile` - and then runs the pytest collection on it, returning the - collection node for the test module. + This writes ``source`` to a file using :py:meth:`makepyfile` and then + runs the pytest collection on it, returning the collection node for the + test module. - :param source: The source code of the module to collect. + :param source: the source code of the module to collect - :param configargs: Any extra arguments to pass to - :py:meth:`parseconfigure`. + :param configargs: any extra arguments to pass to + :py:meth:`parseconfigure` - :param withinit: Whether to also write a ``__init__.py`` file - to the temporary directory to ensure it is a package. + :param withinit: whether to also write an ``__init__.py`` file to the + same directory to ensure it is a package """ kw = {self.request.function.__name__: Source(source).strip()} @@ -871,13 +867,12 @@ def getmodulecol(self, source, configargs=(), withinit=False): def collect_by_name(self, modcol, name): """Return the collection node for name from the module collection. - This will search a module collection node for a collection - node matching the given name. + This will search a module collection node for a collection node + matching the given name. - :param modcol: A module collection node, see - :py:meth:`getmodulecol`. + :param modcol: a module collection node; see :py:meth:`getmodulecol` - :param name: The name of the node to return. + :param name: the name of the node to return """ if modcol not in self._mod_collections: @@ -889,8 +884,8 @@ def collect_by_name(self, modcol, name): def popen(self, cmdargs, stdout, stderr, **kw): """Invoke subprocess.Popen. - This calls subprocess.Popen making sure the current working - directory is the PYTHONPATH. + This calls subprocess.Popen making sure the current working directory + is in the PYTHONPATH. You probably want to use :py:meth:`run` instead. @@ -908,8 +903,7 @@ def popen(self, cmdargs, stdout, stderr, **kw): def run(self, *cmdargs): """Run a command with arguments. - Run a process using subprocess.Popen saving the stdout and - stderr. + Run a process using subprocess.Popen saving the stdout and stderr. Returns a :py:class:`RunResult`. @@ -952,14 +946,15 @@ def _dump_lines(self, lines, fp): 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. a pytest.exe + # we cannot use `(sys.executable, script)` because on Windows the + # script is e.g. `pytest.exe` return (sys.executable, PYTEST_FULLPATH) # noqa def runpython(self, script): """Run a python script using sys.executable as interpreter. Returns a :py:class:`RunResult`. + """ return self.run(sys.executable, script) @@ -970,12 +965,11 @@ def runpython_c(self, command): def runpytest_subprocess(self, *args, **kwargs): """Run pytest as a subprocess with given arguments. - Any plugins added to the :py:attr:`plugins` list will added - using the ``-p`` command line option. Addtionally - ``--basetemp`` is used put any temporary files and directories - in a numbered directory prefixed with "runpytest-" so they do - not conflict with the normal numberd pytest location for - temporary files and directories. + Any plugins added to the :py:attr:`plugins` list will added using the + ``-p`` command line option. Additionally ``--basetemp`` is used put + any temporary files and directories in a numbered directory prefixed + with "runpytest-" so they do not conflict with the normal numbered + pytest location for temporary files and directories. Returns a :py:class:`RunResult`. @@ -998,8 +992,8 @@ def runpytest_subprocess(self, *args, **kwargs): def spawn_pytest(self, string, expect_timeout=10.0): """Run pytest using pexpect. - This makes sure to use the right pytest and sets up the - temporary directory locations. + This makes sure to use the right pytest and sets up the temporary + directory locations. The pexpect child is returned. @@ -1013,6 +1007,7 @@ def spawn(self, cmd, expect_timeout=10.0): """Run a command using pexpect. The pexpect child is returned. + """ pexpect = pytest.importorskip("pexpect", "3.0") if hasattr(sys, 'pypy_version_info') and '64' in platform.machine(): @@ -1039,8 +1034,10 @@ def __init__(self): self.stringio = py.io.TextIO() def assert_contains_lines(self, lines2): - """ assert that lines2 are contained (linearly) in lines1. - return a list of extralines found. + """Assert that lines2 are contained (linearly) in lines1. + + Return a list of extralines found. + """ __tracebackhide__ = True val = self.stringio.getvalue() @@ -1056,8 +1053,8 @@ class LineMatcher: This is a convenience class to test large texts like the output of commands. - The constructor takes a list of lines without their trailing - newlines, i.e. ``text.splitlines()``. + The constructor takes a list of lines without their trailing newlines, i.e. + ``text.splitlines()``. """ @@ -1077,18 +1074,19 @@ def _getlines(self, lines2): return lines2 def fnmatch_lines_random(self, lines2): - """Check lines exist in the output using ``fnmatch.fnmatch``, in any order. + """Check lines exist in the output using in any order. + + Lines are checked using ``fnmatch.fnmatch``. The argument is a list of + lines which have to occur in the output, in any order. - The argument is a list of lines which have to occur in the - output, in any order. """ self._match_lines_random(lines2, fnmatch) def re_match_lines_random(self, lines2): """Check lines exist in the output using ``re.match``, in any order. - The argument is a list of lines which have to occur in the - output, in any order. + The argument is a list of lines which have to occur in the output, in + any order. """ self._match_lines_random(lines2, lambda name, pat: re.match(pat, name)) @@ -1096,8 +1094,8 @@ def re_match_lines_random(self, lines2): def _match_lines_random(self, lines2, match_func): """Check lines exist in the output. - The argument is a list of lines which have to occur in the - output, in any order. Each line can contain glob whildcards. + The argument is a list of lines which have to occur in the output, in + any order. Each line can contain glob whildcards. """ lines2 = self._getlines(lines2) @@ -1114,6 +1112,7 @@ def get_lines_after(self, fnline): """Return all lines following the given line in the text. The given line can contain glob wildcards. + """ for i, line in enumerate(self.lines): if fnline == line or fnmatch(line, fnline): @@ -1130,10 +1129,9 @@ def _log_text(self): def fnmatch_lines(self, lines2): """Search captured text for matching lines using ``fnmatch.fnmatch``. - The argument is a list of lines which have to match and can - use glob wildcards. If they do not match a pytest.fail() is - called. The matches and non-matches are also printed on - stdout. + The argument is a list of lines which have to match and can use glob + wildcards. If they do not match a pytest.fail() is called. The + matches and non-matches are also printed on stdout. """ self._match_lines(lines2, fnmatch, 'fnmatch') @@ -1144,21 +1142,22 @@ def re_match_lines(self, lines2): The argument is a list of lines which have to match using ``re.match``. If they do not match a pytest.fail() is called. - The matches and non-matches are also printed on - stdout. + The matches and non-matches are also printed on stdout. + """ self._match_lines(lines2, lambda name, pat: re.match(pat, name), 're.match') def _match_lines(self, lines2, match_func, match_nickname): """Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``. - :param list[str] lines2: list of string patterns to match. The actual format depends on - ``match_func``. - :param match_func: a callable ``match_func(line, pattern)`` where line is the captured - line from stdout/stderr and pattern is the matching pattern. + :param list[str] lines2: list of string patterns to match. The actual + format depends on ``match_func`` + :param match_func: a callable ``match_func(line, pattern)`` where line + is the captured line from stdout/stderr and pattern is the matching + pattern + :param str match_nickname: the nickname for the match function that + will be logged to stdout when a match occurs - :param str match_nickname: the nickname for the match function that will be logged - to stdout when a match occurs. """ lines2 = self._getlines(lines2) lines1 = self.lines[:] From 57fcd3f57e824249b8786df5e75748673f3273ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Fri, 8 Dec 2017 20:06:22 +0100 Subject: [PATCH 02/11] remove corpse code comments --- _pytest/pytester.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 70436b24690..6e37d8b3179 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -27,7 +27,6 @@ def pytest_addoption(parser): - # group = parser.getgroup("pytester", "pytester (self-tests) options") parser.addoption('--lsof', action="store_true", dest="lsof", default=False, help=("run FD checks if lsof is available")) @@ -977,12 +976,6 @@ def runpytest_subprocess(self, *args, **kwargs): p = py.path.local.make_numbered_dir(prefix="runpytest-", keep=None, rootdir=self.tmpdir) args = ('--basetemp=%s' % p, ) + args - # for x in args: - # if '--confcutdir' in str(x): - # break - # else: - # pass - # args = ('--confcutdir=.',) + args plugins = [x for x in self.plugins if isinstance(x, str)] if plugins: args = ('-p', plugins[0]) + args From 596937e610719fcaf7269959d8b20d49b6381c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Fri, 8 Dec 2017 20:17:14 +0100 Subject: [PATCH 03/11] remove extra whitespace --- _pytest/pytester.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 6e37d8b3179..0b25d839b93 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -32,7 +32,7 @@ def pytest_addoption(parser): help=("run FD checks if lsof is available")) parser.addoption('--runpytest', default="inprocess", dest="runpytest", - choices=("inprocess", "subprocess", ), + choices=("inprocess", "subprocess"), help=("run pytest sub runs in tests using an 'inprocess' " "or 'subprocess' (python -m main) method")) @@ -975,7 +975,7 @@ def runpytest_subprocess(self, *args, **kwargs): """ p = py.path.local.make_numbered_dir(prefix="runpytest-", keep=None, rootdir=self.tmpdir) - args = ('--basetemp=%s' % p, ) + args + args = ('--basetemp=%s' % p,) + args plugins = [x for x in self.plugins if isinstance(x, str)] if plugins: args = ('-p', plugins[0]) + args From f0bfe9de3d957867c56a4b7b514226d992049c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Fri, 1 Dec 2017 13:28:39 +0100 Subject: [PATCH 04/11] shorten some test code --- testing/acceptance_test.py | 4 ++-- testing/test_conftest.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index a7838545b07..21d17453b13 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -215,8 +215,8 @@ def test_chdir(self, testdir): assert not result.ret def test_issue109_sibling_conftests_not_loaded(self, testdir): - sub1 = testdir.tmpdir.mkdir("sub1") - sub2 = testdir.tmpdir.mkdir("sub2") + sub1 = testdir.mkdir("sub1") + sub2 = testdir.mkdir("sub2") sub1.join("conftest.py").write("assert 0") result = testdir.runpytest(sub2) assert result.ret == EXIT_NOTESTSCOLLECTED diff --git a/testing/test_conftest.py b/testing/test_conftest.py index c0411b72321..dd54e0c5b0e 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -84,7 +84,7 @@ def test_conftest_in_nonpkg_with_init(tmpdir): def test_doubledash_considered(testdir): conf = testdir.mkdir("--option") - conf.join("conftest.py").ensure() + conf.ensure("conftest.py") conftest = PytestPluginManager() conftest_setinitial(conftest, [conf.basename, conf.basename]) values = conftest._getconftestmodules(conf) From 7feab7391d2e4e53829f29fe898e3169b5a5b3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Wed, 6 Dec 2017 15:22:45 +0100 Subject: [PATCH 05/11] simplify test_pdb_collection_failure_is_shown test data setup code --- testing/test_pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 70a5c3c5bdb..a565cbd0df2 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -338,7 +338,7 @@ def test_foo(a): self.flush(child) def test_pdb_collection_failure_is_shown(self, testdir): - p1 = testdir.makepyfile("""xxx """) + p1 = testdir.makepyfile("xxx") result = testdir.runpytest_subprocess("--pdb", p1) result.stdout.fnmatch_lines([ "*NameError*xxx*", From 41a6ec6f317965b4546ddc50d2ffcde259546fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Fri, 8 Dec 2017 21:27:53 +0100 Subject: [PATCH 06/11] touch up test_cmdline_python_namespace_package() test code --- testing/acceptance_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 21d17453b13..ff3dda4e513 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -624,10 +624,9 @@ def join_pythonpath(*dirs): for p in search_path: monkeypatch.syspath_prepend(p) - os.chdir('world') # mixed module and filenames: + os.chdir('world') result = testdir.runpytest("--pyargs", "-v", "ns_pkg.hello", "ns_pkg/world") - testdir.chdir() assert result.ret == 0 result.stdout.fnmatch_lines([ "*test_hello.py::test_hello*PASSED*", @@ -638,6 +637,7 @@ def join_pythonpath(*dirs): ]) # specify tests within a module + testdir.chdir() result = testdir.runpytest("--pyargs", "-v", "ns_pkg.world.test_world::test_other") assert result.ret == 0 result.stdout.fnmatch_lines([ From dd64f1a4a9b5443aeeb5ec9f4aecc970bd71151d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Fri, 8 Dec 2017 23:34:00 +0100 Subject: [PATCH 07/11] fix tox.ini comment typos --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 900b602dc33..38ebaf69fac 100644 --- a/tox.ini +++ b/tox.ini @@ -138,7 +138,7 @@ commands = basepython = python usedevelop = True skipsdist = True -# ensure the given pyargs cant mean anytrhing else +# ensure the given pyargs can't mean anything else changedir = doc/ deps = PyYAML From 852b96714e2f64826ae293657f20ec88c769f6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Fri, 8 Dec 2017 23:48:58 +0100 Subject: [PATCH 08/11] use spaces consistently instead of some of them being   --- testing/acceptance_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index ff3dda4e513..b4277e46dbc 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -603,11 +603,11 @@ def test_cmdline_python_namespace_package(self, testdir, monkeypatch): # The structure of the test directory is now: # . # ├── hello - # │   └── ns_pkg - # │   ├── __init__.py - # │   └── hello - # │   ├── __init__.py - # │   └── test_hello.py + # │ └── ns_pkg + # │ ├── __init__.py + # │ └── hello + # │ ├── __init__.py + # │ └── test_hello.py # └── world # └── ns_pkg # ├── __init__.py From 8e8a953ac67b74c2ee4ccefe9afa7abbd886cbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Sat, 9 Dec 2017 13:31:12 +0100 Subject: [PATCH 09/11] fix test name typo --- testing/test_pytester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 9508c2954e8..cba267f5774 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -141,7 +141,7 @@ def test_inline_run_clean_modules(testdir): assert result2.ret == EXIT_TESTSFAILED -def test_assert_outcomes_after_pytest_erro(testdir): +def test_assert_outcomes_after_pytest_error(testdir): testdir.makepyfile("def test_foo(): assert True") result = testdir.runpytest('--unexpected-argument') From 73bc6bacfa20ca783c46e7a6169b07e294b90fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Fri, 8 Dec 2017 23:09:52 +0100 Subject: [PATCH 10/11] add changelog entry --- changelog/3015.trivial | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/3015.trivial diff --git a/changelog/3015.trivial b/changelog/3015.trivial new file mode 100644 index 00000000000..a63ba06e6d3 --- /dev/null +++ b/changelog/3015.trivial @@ -0,0 +1 @@ +Code cleanup. From 3b85e0c3a985427376429a36b81e1aaea55c0887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Mon, 11 Dec 2017 15:10:04 +0100 Subject: [PATCH 11/11] simplify test_conftest_found_with_double_dash() test code --- testing/test_conftest.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/testing/test_conftest.py b/testing/test_conftest.py index dd54e0c5b0e..f0f187606c2 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -270,11 +270,7 @@ def pytest_addoption(parser): parser.addoption("--hello-world", action="store_true") """)) p = sub.join("test_hello.py") - p.write(py.std.textwrap.dedent(""" - import pytest - def test_hello(found): - assert found == 1 - """)) + p.write("def test_hello(): pass") result = testdir.runpytest(str(p) + "::test_hello", "-h") result.stdout.fnmatch_lines(""" *--hello-world*