From ca44e88e5404308e6be54e645916e5483a30602d Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 4 Jun 2015 07:52:25 +0200 Subject: [PATCH 01/12] backport fixed issue735 --HG-- branch : pytest-2.7 --- CHANGELOG | 6 ++++++ _pytest/assertion/rewrite.py | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 3e1bccc46..334bf8b6f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +2.7.2 (compared to 2.7.1) +----------------------------- + +- fix issue735: assertion failures on debug versions of Python 3.4+ + Thanks Benjamin Peterson. + 2.7.1 (compared to 2.7.0) ----------------------------- diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index f965ba2c3..62046d146 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -442,6 +442,13 @@ binop_map = { ast.NotIn: "not in" } +# Python 3.4+ compatibility +if hasattr(ast, "NameConstant"): + _NameConstant = ast.NameConstant +else: + def _NameConstant(c): + return ast.Name(str(c), ast.Load()) + def set_location(node, lineno, col_offset): """Set node location information recursively.""" @@ -680,7 +687,7 @@ class AssertionRewriter(ast.NodeVisitor): if self.variables: variables = [ast.Name(name, ast.Store()) for name in self.variables] - clear = ast.Assign(variables, ast.Name("None", ast.Load())) + clear = ast.Assign(variables, _NameConstant(None)) self.statements.append(clear) # Fix line numbers. for stmt in self.statements: From f04e01f55f388c38ad38dae42dd0b11519c58cfd Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 16 Jun 2015 21:20:43 -0300 Subject: [PATCH 02/12] Sort AUTHORS names --- AUTHORS | 74 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/AUTHORS b/AUTHORS index abe29c261..85cb3c47f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,48 +3,48 @@ merlinux GmbH, Germany, office at merlinux eu Contributors include:: -Ronny Pfannschmidt -Benjamin Peterson -Floris Bruynooghe -Jason R. Coombs -Wouter van Ackooy -Samuele Pedroni Anatoly Bubenkoff +Andreas Zeidler +Andy Freeland +Anthon van der Neut +Armin Rigo +Benjamin Peterson +Bob Ippolito +Brian Dorsey +Brian Okken Brianna Laugher Carl Friedrich Bolz -Armin Rigo -Maho -Jaap Broekhuizen -Maciek Fijalkowski -Guido Wesdorp -Brian Dorsey -Ross Lawley -Ralf Schmitt +Charles Cloud Chris Lamb -Harald Armin Massa -Martijn Faassen -Ian Bicking -Jan Balster -Grig Gheorghiu -Bob Ippolito -Christian Tismer -Daniel Nuri -Graham Horler -Andreas Zeidler -Brian Okken -Katarzyna Jachim Christian Theunert -Anthon van der Neut -Mark Abramowitz -Piotr Banaszkiewicz -Jurko Gospodnetić -Marc Schlaich +Christian Tismer Christopher Gilling Daniel Grana -Andy Freeland -Trevor Bekolay -David Mohr -Nicolas Delaby -Tom Viner +Daniel Nuri Dave Hunt -Charles Cloud +David Mohr +Floris Bruynooghe +Graham Horler +Grig Gheorghiu +Guido Wesdorp +Harald Armin Massa +Ian Bicking +Jaap Broekhuizen +Jan Balster +Jason R. Coombs +Jurko Gospodnetić +Katarzyna Jachim +Maciek Fijalkowski +Maho +Marc Schlaich +Mark Abramowitz +Martijn Faassen +Nicolas Delaby +Piotr Banaszkiewicz +Ralf Schmitt +Ronny Pfannschmidt +Ross Lawley +Samuele Pedroni +Tom Viner +Trevor Bekolay +Wouter van Ackooy From 0c05b906d4f82d36d2dded48bc96c1e3902bf9c6 Mon Sep 17 00:00:00 2001 From: Punyashloka Biswal Date: Tue, 16 Jun 2015 16:35:31 -0400 Subject: [PATCH 03/12] backport fix for #713 --- AUTHORS | 1 + CHANGELOG | 3 +++ _pytest/junitxml.py | 6 ++++-- testing/test_doctest.py | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 85cb3c47f..fc434fca5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -41,6 +41,7 @@ Mark Abramowitz Martijn Faassen Nicolas Delaby Piotr Banaszkiewicz +Punyashloka Biswal Ralf Schmitt Ronny Pfannschmidt Ross Lawley diff --git a/CHANGELOG b/CHANGELOG index 334bf8b6f..952694d7b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ 2.7.2 (compared to 2.7.1) ----------------------------- +- fix issue713: JUnit XML reports for doctest failures. + Thanks Punyashloka Biswal. + - fix issue735: assertion failures on debug versions of Python 3.4+ Thanks Benjamin Peterson. diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 6d25d8407..ef07c7a08 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -123,10 +123,12 @@ class LogXML(object): Junit.skipped(message="xfail-marked test passes unexpectedly")) self.skipped += 1 else: - if isinstance(report.longrepr, (unicode, str)): + if hasattr(report.longrepr, "reprcrash"): + message = report.longrepr.reprcrash.message + elif isinstance(report.longrepr, (unicode, str)): message = report.longrepr else: - message = report.longrepr.reprcrash.message + message = str(report.longrepr) message = bin_xml_escape(message) fail = Junit.failure(message=message) fail.append(bin_xml_escape(report.longrepr)) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index c1139f773..2bf6d2450 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -354,3 +354,19 @@ class TestDoctests: reprec = testdir.inline_run(p, "--doctest-modules", "--doctest-ignore-import-errors") reprec.assertoutcome(skipped=1, failed=1, passed=0) + + def test_junit_report_for_doctest(self, testdir): + """ + #713: Fix --junit-xml option when used with --doctest-modules. + """ + p = testdir.makepyfile(""" + def foo(): + ''' + >>> 1 + 1 + 3 + ''' + pass + """) + reprec = testdir.inline_run(p, "--doctest-modules", + "--junit-xml=junit.xml") + reprec.assertoutcome(failed=1) From 1db5c95414480cdb21804d7d8ef898a5f69b7c34 Mon Sep 17 00:00:00 2001 From: curzona Date: Tue, 16 Jun 2015 14:36:18 -0700 Subject: [PATCH 04/12] Automatically create directory for results --- _pytest/junitxml.py | 3 +++ _pytest/resultlog.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 6d25d8407..a248a0715 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -203,6 +203,9 @@ class LogXML(object): self.suite_start_time = time.time() def pytest_sessionfinish(self): + dirname = os.path.dirname(os.path.abspath(self.logfile)) + if not os.path.exists(dirname): + os.makedirs(dirname) logfile = open(self.logfile, 'w', encoding='utf-8') suite_stop_time = time.time() suite_time_delta = suite_stop_time - self.suite_start_time diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py index 0c100552f..44312d319 100644 --- a/_pytest/resultlog.py +++ b/_pytest/resultlog.py @@ -3,6 +3,7 @@ text file. """ import py +import os def pytest_addoption(parser): group = parser.getgroup("terminal reporting", "resultlog plugin options") @@ -14,6 +15,9 @@ def pytest_configure(config): resultlog = config.option.resultlog # prevent opening resultlog on slave nodes (xdist) if resultlog and not hasattr(config, 'slaveinput'): + dirname = os.path.dirname(os.path.abspath(resultlog)) + if not os.path.exists(dirname): + os.makedirs(dirname) logfile = open(resultlog, 'w', 1) # line buffered config._resultlog = ResultLog(config, logfile) config.pluginmanager.register(config._resultlog) From 9346e18d8c2e611747fe2b7c82ab6f0ae38aec55 Mon Sep 17 00:00:00 2001 From: curzona Date: Tue, 16 Jun 2015 15:36:04 -0700 Subject: [PATCH 05/12] Test creating directory for junit-xml and resultlog --- testing/test_junitxml.py | 9 +++++++++ testing/test_resultlog.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 9da836bbe..65e3ca03f 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -474,6 +474,15 @@ def test_logxml_changingdir(testdir): assert result.ret == 0 assert testdir.tmpdir.join("a/x.xml").check() +def test_logxml_makedir(testdir): + testdir.makepyfile(""" + def test_pass(): + pass + """) + result = testdir.runpytest("--junitxml=path/to/results.xml") + assert result.ret == 0 + assert testdir.tmpdir.join("path/to/results.xml").check() + def test_escaped_parametrized_names_xml(testdir): testdir.makepyfile(""" import pytest diff --git a/testing/test_resultlog.py b/testing/test_resultlog.py index e4f3faccc..96686d3a2 100644 --- a/testing/test_resultlog.py +++ b/testing/test_resultlog.py @@ -180,6 +180,20 @@ def test_generic(testdir, LineMatcher): "x *:test_xfail_norun", ]) +def test_makedir_for_resultlog(testdir, LineMatcher): + testdir.plugins.append("resultlog") + testdir.makepyfile(""" + import pytest + def test_pass(): + pass + """) + testdir.runpytest("--resultlog=path/to/result.log") + lines = testdir.tmpdir.join("path/to/result.log").readlines(cr=0) + LineMatcher(lines).fnmatch_lines([ + ". *:test_pass", + ]) + + def test_no_resultlog_on_slaves(testdir): config = testdir.parseconfig("-p", "resultlog", "--resultlog=resultlog") From 1871d526ace55bad1cffc0ca9d8b652a6a6c10ab Mon Sep 17 00:00:00 2001 From: curzona Date: Tue, 16 Jun 2015 15:37:17 -0700 Subject: [PATCH 06/12] Update CHANGELOG and AUTHORS --- AUTHORS | 1 + CHANGELOG | 3 +++ 2 files changed, 4 insertions(+) diff --git a/AUTHORS b/AUTHORS index abe29c261..0b59555f0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -48,3 +48,4 @@ Nicolas Delaby Tom Viner Dave Hunt Charles Cloud +Aron Curzon diff --git a/CHANGELOG b/CHANGELOG index 334bf8b6f..c12bcce7c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ 2.7.2 (compared to 2.7.1) ----------------------------- +- Automatically create directory for junitxml and results log. + Thanks Aron Curzon. + - fix issue735: assertion failures on debug versions of Python 3.4+ Thanks Benjamin Peterson. From af77a23501611302bdeeec66c02390b9e5762689 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 17 Jun 2015 00:04:25 -0300 Subject: [PATCH 07/12] Add docs for new tests --- testing/test_junitxml.py | 1 + testing/test_resultlog.py | 1 + 2 files changed, 2 insertions(+) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 65e3ca03f..d019f87cc 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -475,6 +475,7 @@ def test_logxml_changingdir(testdir): assert testdir.tmpdir.join("a/x.xml").check() def test_logxml_makedir(testdir): + """--junitxml should automatically create directories for the xml file""" testdir.makepyfile(""" def test_pass(): pass diff --git a/testing/test_resultlog.py b/testing/test_resultlog.py index 96686d3a2..ef1d6d040 100644 --- a/testing/test_resultlog.py +++ b/testing/test_resultlog.py @@ -181,6 +181,7 @@ def test_generic(testdir, LineMatcher): ]) def test_makedir_for_resultlog(testdir, LineMatcher): + """--resultlog should automatically create directories for the log file""" testdir.plugins.append("resultlog") testdir.makepyfile(""" import pytest From ae89436d9734fea6057a0dc07e61ddd698343871 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 17 Jun 2015 00:05:56 -0300 Subject: [PATCH 08/12] Remove duplicated author from AUTHORS --- AUTHORS | 1 - 1 file changed, 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index eab95f75a..bb5fec0d6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -23,7 +23,6 @@ Christopher Gilling Daniel Grana Daniel Nuri Dave Hunt -Dave Hunt David Mohr Floris Bruynooghe Graham Horler From 0722b95e53f80b960909905f48937460a1b0b746 Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Tue, 16 Jun 2015 00:22:16 +0200 Subject: [PATCH 09/12] use travis containers --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 1c865fb9e..0c6e61bc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: python # command to install dependencies install: "pip install -U detox" From 73f37d098983bec9de7be7c75827840bab6bf24c Mon Sep 17 00:00:00 2001 From: Anatoly Bubenkov Date: Tue, 16 Jun 2015 00:40:49 +0200 Subject: [PATCH 10/12] split travis jobs Conflicts: README.rst --- .travis.yml | 25 +++++++++++++++++++++++-- tox.ini | 12 ++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c6e61bc9..175bd0222 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,30 @@ sudo: false language: python # command to install dependencies -install: "pip install -U detox" +install: "pip install -U tox" # # command to run tests -script: detox --recreate -i ALL=https://devpi.net/hpk/dev/ +env: + matrix: + - TESTENV=flakes + - TESTENV=py26 + - TESTENV=py27 + - TESTENV=py34 + - TESTENV=pypy + - TESTENV=py27-pexpect + - TESTENV=py33-pexpect + - TESTENV=py27-nobyte + - TESTENV=py33 + - TESTENV=py27-xdist + - TESTENV=py33-xdist + - TESTENV=py27 + - TESTENV=py27-trial + - TESTENV=py33 + - TESTENV=py33-trial + - TESTENV=py27-subprocess + - TESTENV=doctesting + - TESTENV=py27-cxfreeze + - TESTENV=coveralls +script: tox --recreate -i ALL=https://devpi.net/hpk/dev/ -e $TESTENV notifications: irc: diff --git a/tox.ini b/tox.ini index 9f683c46f..0e315c03b 100644 --- a/tox.ini +++ b/tox.ini @@ -132,6 +132,18 @@ commands= {envpython} runtests_setup.py build --build-exe build {envpython} tox_run.py +[testenv:coveralls] +changedir=testing +basepython=python3.4 +deps = + {[testenv]deps} + coveralls +commands= + coverage run --source=_pytest {envdir}/bin/py.test + coverage report -m + coveralls +passenv=COVERALLS_REPO_TOKEN + [pytest] minversion=2.0 plugins=pytester From 923174718efe4f16256b1978ef64b6f4dbd2fce0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 17 Jun 2015 00:44:31 -0300 Subject: [PATCH 11/12] Allow failure of py27-subprocess tox-env while on pytest-2.7 "inprocess by default" was introduced in 2.8, and the current travis configuration was backported from master so this specific tox-env will remain disabled while pytest-2.7 maintenance branch lasts. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 175bd0222..a6fc5757d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,9 @@ env: - TESTENV=py27-trial - TESTENV=py33 - TESTENV=py33-trial - - TESTENV=py27-subprocess + # inprocess tests by default were introduced in 2.8 only; + # this TESTENV should be enabled when merged back to master + #- TESTENV=py27-subprocess - TESTENV=doctesting - TESTENV=py27-cxfreeze - TESTENV=coveralls From 26530244097796ae0766c63215f871cd7665aefc Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 17 Jun 2015 08:08:03 -0300 Subject: [PATCH 12/12] Use os.path.isdir instead of os.path.exists As suggested during review --- _pytest/junitxml.py | 2 +- _pytest/resultlog.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 84a872e4a..8f6c36ff9 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -206,7 +206,7 @@ class LogXML(object): def pytest_sessionfinish(self): dirname = os.path.dirname(os.path.abspath(self.logfile)) - if not os.path.exists(dirname): + if not os.path.isdir(dirname): os.makedirs(dirname) logfile = open(self.logfile, 'w', encoding='utf-8') suite_stop_time = time.time() diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py index 44312d319..3670f0214 100644 --- a/_pytest/resultlog.py +++ b/_pytest/resultlog.py @@ -16,7 +16,7 @@ def pytest_configure(config): # prevent opening resultlog on slave nodes (xdist) if resultlog and not hasattr(config, 'slaveinput'): dirname = os.path.dirname(os.path.abspath(resultlog)) - if not os.path.exists(dirname): + if not os.path.isdir(dirname): os.makedirs(dirname) logfile = open(resultlog, 'w', 1) # line buffered config._resultlog = ResultLog(config, logfile)