diff --git a/.travis.yml b/.travis.yml index 91a032d..3be2500 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: python python: - - "2.6" - "2.7" - - "3.4" - - "3.5" - "3.6" install: - pip install tox tox-travis codecov diff --git a/pytest_marker_bugzilla.py b/pytest_marker_bugzilla.py index 54b05eb..ab2822b 100644 --- a/pytest_marker_bugzilla.py +++ b/pytest_marker_bugzilla.py @@ -142,32 +142,28 @@ def pytest_runtest_setup(self, item): """ if "bugzilla" not in item.keywords: return + bugs = item.funcargs["bugs"] - will_skip = True skippers = [] - for bug in bugs.bugs_gen: - if bug.status not in ["NEW", "ASSIGNED", "ON_DEV"]: - will_skip = False - else: - skippers.append(bug) + for bz in bugs.bugs_gen: + if bz.status in ["NEW", "ASSIGNED", "ON_DEV"]: + skippers.append(bz) + url = "{0}?id=".format( self.bugzilla.url.replace("xmlrpc.cgi", "show_bug.cgi"), ) - if will_skip: + if skippers: pytest.skip( "Skipping this test because all of these assigned bugs:\n" "{0}".format( "\n".join( - [ - "{0} {1}{2}".format(bug.status, url, bug.id) - for bug in skippers - ] + ["{0} {1}{2}".format(bug.status, url, bug.id)for bug in skippers] ) ) ) - marker = item.get_marker('bugzilla') + marker = item.get_closest_marker(name='bugzilla') xfail = kwargify(marker.kwargs.get("xfail_when", lambda: False)) skip = kwargify(marker.kwargs.get("skip_when", lambda: False)) if skip: @@ -190,8 +186,8 @@ def pytest_runtest_setup(self, item): ) def evaluate_skip(self, skip, bugs): - for bug in bugs.bugs_gen: - context = {"bug": bug} + for bz in bugs.bugs_gen: + context = {"bug": bz} if self.version: context["version"] = LooseVersion(self.version) if skip(**context): @@ -203,12 +199,12 @@ def evaluate_skip(self, skip, bugs): def evaluate_xfail(self, xfail, bugs): results = [] - for bug in bugs.bugs_gen: - context = {"bug": bug} + for bz in bugs.bugs_gen: + context = {"bug": bz} if self.version: context["version"] = LooseVersion(self.version) if xfail(**context): - results.append(bug) + results.append(bz) return results def pytest_collection_modifyitems(self, session, config, items): @@ -217,17 +213,15 @@ def pytest_collection_modifyitems(self, session, config, items): if reporter: reporter.write("Checking for bugzilla-related tests\n", bold=True) cache = {} - for i, item in enumerate( - filter(lambda i: i.get_marker("bugzilla") is not None, items) - ): - marker = item.get_marker('bugzilla') - # (O_O) for caching - bugs = tuple(sorted(set(map(int, marker.args)))) - if bugs not in cache: - if reporter: - reporter.write(".") - cache[bugs] = BugzillaBugs(self.bugzilla, self.loose, *bugs) - item.funcargs["bugs"] = cache[bugs] + for item in items: + for marker in item.iter_markers(name='bugzilla'): + bugs = tuple(sorted(set(map(int, marker.args)))) + if bugs not in cache: + if reporter: + reporter.write(".") + cache[bugs] = BugzillaBugs(self.bugzilla, self.loose, *bugs) + item.funcargs["bugs"] = cache[bugs] + if reporter: reporter.write( "\nChecking for bugzilla-related tests has finished\n", diff --git a/setup.cfg b/setup.cfg index 1ae1815..1208023 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,12 +20,7 @@ classifiers= Operating System :: Microsoft :: Windows Operating System :: MacOS :: MacOS X Programming Language :: Python - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.6 Programming Language :: Python :: 2.7 - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Topic :: Software Development :: Testing Topic :: Software Development :: Quality Assurance diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index e00de0a..0000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pytest-xdist -coverage diff --git a/tests/test_bugzilla.py b/tests/test_bugzilla.py index b0c3ef8..208111a 100644 --- a/tests/test_bugzilla.py +++ b/tests/test_bugzilla.py @@ -15,6 +15,8 @@ "fixed_in": None, "status": 'NEW', "target_release": None, + "resolution": 'foo 1', + "summary": 'ONE', }, "2": { "id": 2, @@ -22,6 +24,8 @@ "fixed_in": None, "status": 'CLOSED', "target_release": None, + "resolution": 'foo 2', + "summary": 'TWO', }, "3": { "id": 3, @@ -29,6 +33,8 @@ "fixed_in": 2.0, "status": 'POST', "target_release": None, + "resolution": 'foo 3', + "summary": 'THREE', }, "4": { "id": 4, @@ -36,6 +42,8 @@ "fixed_in": None, "status": 'NEW', "target_release": None, + "resolution": 'foo 4', + "summary": 'FOUR', }, } @@ -177,21 +185,21 @@ def test_closed_bug_with_failure(): result.assert_outcomes(1, 1, 1) -def test_multiple_bugs_failure(testdir): +def test_multiple_bugs_skip_1(testdir): testdir.makeconftest(CONFTEST) testdir.makepyfile(""" import os import pytest - @pytest.mark.bugzilla('1', '2', '4') + @pytest.mark.bugzilla('1', '4', '2') def test_new_bug(): assert(os.path.exists('/etcccc')) """) result = testdir.runpytest(*BUGZILLA_ARGS) - result.assert_outcomes(0, 0, 1) + result.assert_outcomes(0, 1, 0) -def test_multiple_bugs_skip(testdir): +def test_multiple_bugs_skip_2(testdir): testdir.makeconftest(CONFTEST) testdir.makepyfile(""" import os @@ -225,10 +233,7 @@ def test_xfail_when_feature(testdir): import os import pytest - @pytest.mark.bugzilla( - '3', - xfail_when=lambda bug, version: bug.fixed_in > version - ) + @pytest.mark.bugzilla('3', xfail_when=lambda bug, version: bug.fixed_in > version) def test_new_bug(): assert(os.path.exists('/etcccc')) """) diff --git a/tox.ini b/tox.ini index 33d14ce..e31e5de 100644 --- a/tox.ini +++ b/tox.ini @@ -1,20 +1,28 @@ [tox] -envlist = py26,py27,py34,pep8 +envlist = py{27,36}-pytest{361,431} + [tox:travis] -2.6 = py26 -2.7 = py27, pep8 -3.4 = py34, pep8 -3.5 = py35, pep8 -3.6 = py36, pep8 +2.7 = py27-pytest361, py27-pytest431, pep8 +3.6 = py36-pytest361, py36-pytest431, pep8 + [testenv] -deps= - -rrequirements.txt - -rtests/requirements.txt -setenv = - PYTEST_ADDOPTS=-p pytester --basetemp={envtmpdir} +deps = + pytest361: pytest==3.6.1 + pytest431: pytest==4.3.1 + pytest-xdist + pytest-cov commands= - coverage run --source pytest_marker_bugzilla -m py.test - coverage report + pytest \ + --basetemp={envtmpdir} \ + -p pytester \ + --cov pytest_marker_bugzilla \ + --cov-report term \ + --cov-report html \ + {posargs} + +[flake8] +max-line-length = 120 + [testenv:pep8] deps=flake8 commands=flake8 pytest_marker_bugzilla.py tests