Skip to content

Commit

Permalink
Merge pull request #41 from myakove/py3-fix
Browse files Browse the repository at this point in the history
Some fixes for py3
  • Loading branch information
els-pnw authored May 22, 2019
2 parents 5e85a7c + 41a5577 commit 5042b5d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 59 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: python
python:
- "2.6"
- "2.7"
- "3.4"
- "3.5"
- "3.6"
install:
- pip install tox tox-travis codecov
Expand Down
50 changes: 22 additions & 28 deletions pytest_marker_bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/requirements.txt

This file was deleted.

21 changes: 13 additions & 8 deletions tests/test_bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,35 @@
"fixed_in": None,
"status": 'NEW',
"target_release": None,
"resolution": 'foo 1',
"summary": 'ONE',
},
"2": {
"id": 2,
"version": None,
"fixed_in": None,
"status": 'CLOSED',
"target_release": None,
"resolution": 'foo 2',
"summary": 'TWO',
},
"3": {
"id": 3,
"version": 1.0,
"fixed_in": 2.0,
"status": 'POST',
"target_release": None,
"resolution": 'foo 3',
"summary": 'THREE',
},
"4": {
"id": 4,
"version": None,
"fixed_in": None,
"status": 'NEW',
"target_release": None,
"resolution": 'foo 4',
"summary": 'FOUR',
},
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'))
""")
Expand Down
34 changes: 21 additions & 13 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5042b5d

Please sign in to comment.