Skip to content

Commit 83c9777

Browse files
authored
Fix tests for pytest 5 (microsoft#13775)
1 parent c4e65e3 commit 83c9777

File tree

12 files changed

+334
-286
lines changed

12 files changed

+334
-286
lines changed

build/test-requirements.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ pycodestyle
1010
prospector==1.2.0 # Last version of prospector with Python 2.7 support
1111
pydocstyle
1212
nose
13-
pytest==4.6.9 # Last version of pytest with Python 2.7 support
14-
py==1.8.1
13+
pytest < 6.0.0; python_version > '2.7' # Tests do not support pytest 6 yet.
1514
rope
1615
flask
1716
django
1817
isort
19-
pathlib2>=2.2.0 ; python_version<'3.6' # Python 2.7 compatibility (pytest)
18+
# Python 2.7 compatibility (pytest)
19+
pytest==4.6.9; python_version == '2.7'
20+
pathlib2>=2.2.0; python_version == '2.7'
21+
py==1.8.1; python_version == '2.7'

news/3 Code Health/13726.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a test failure and warning when running test adapter tests under pytest 5

pythonFiles/testing_tools/adapter/info.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from collections import namedtuple
55

66

7-
class TestPath(namedtuple("TestPath", "root relfile func sub")):
7+
class SingleTestPath(namedtuple("TestPath", "root relfile func sub")):
88
"""Where to find a single test."""
99

1010
def __new__(cls, root, relfile, func, sub=None):
11-
self = super(TestPath, cls).__new__(
11+
self = super(SingleTestPath, cls).__new__(
1212
cls,
1313
str(root) if root else None,
1414
str(relfile) if relfile else None,
@@ -62,14 +62,16 @@ def __init__(self, *args, **kwargs):
6262
raise TypeError("missing relpath")
6363

6464

65-
class TestInfo(namedtuple("TestInfo", "id name path source markers parentid kind")):
65+
class SingleTestInfo(
66+
namedtuple("TestInfo", "id name path source markers parentid kind")
67+
):
6668
"""Info for a single test."""
6769

6870
MARKERS = ("skip", "skip-if", "expected-failure")
6971
KINDS = ("function", "doctest")
7072

7173
def __new__(cls, id, name, path, source, markers, parentid, kind="function"):
72-
self = super(TestInfo, cls).__new__(
74+
self = super(SingleTestInfo, cls).__new__(
7375
cls,
7476
str(id) if id else None,
7577
str(name) if name else None,

pythonFiles/testing_tools/adapter/pytest/_pytest_item.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
import _pytest.doctest
100100
import _pytest.unittest
101101

102-
from ..info import TestInfo, TestPath
102+
from ..info import SingleTestInfo, SingleTestPath
103103
from ..util import fix_fileid, PATH_SEP, NORMCASE
104104

105105

@@ -207,10 +207,10 @@ def parse_item(
207207
markers.add("expected-failure")
208208
# We can add support for other markers as we need them?
209209

210-
test = TestInfo(
210+
test = SingleTestInfo(
211211
id=nodeid,
212212
name=item.name,
213-
path=TestPath(
213+
path=SingleTestPath(
214214
root=testroot,
215215
relfile=relfile,
216216
func=testfunc,

pythonFiles/testing_tools/adapter/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT License.
33

44
import contextlib
5+
import io
56

67
try:
78
from io import StringIO
@@ -180,7 +181,7 @@ def _replace_fd(file, target):
180181
"""
181182
try:
182183
fd = file.fileno()
183-
except AttributeError:
184+
except (AttributeError, io.UnsupportedOperation):
184185
# `file` does not have fileno() so it's been replaced from the
185186
# default sys.stdout, etc. Return with noop.
186187
yield

0 commit comments

Comments
 (0)