Skip to content

Commit 5d86d81

Browse files
authored
MNT: use pathlib.Path (#67)
1 parent a2b29b7 commit 5d86d81

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

conftest.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
from packaging.version import Version
1313

1414

15-
def pytest_collect_file(parent, path):
16-
if path.ext == ".ipynb":
17-
return NotebookFile.from_parent(parent, fspath=path)
15+
def pytest_collect_file(parent, file_path):
16+
if file_path.suffix == ".ipynb":
17+
return NotebookFile.from_parent(parent, path=file_path)
1818

1919

2020
class NotebookFile(pytest.File):
2121
if Version(pytest.__version__) < Version("5.4.0"):
2222

2323
@classmethod
24-
def from_parent(cls, parent, fspath):
25-
return cls(parent=parent, fspath=fspath)
24+
def from_parent(cls, parent, path):
25+
return cls(parent=parent, path=path)
2626

2727
def collect(self):
28-
for f in [self.fspath]:
28+
for f in [self.path]:
2929
yield NotebookItem.from_parent(self, name=os.path.basename(f))
3030

3131
def setup(self):
@@ -44,7 +44,7 @@ def from_parent(cls, parent, name):
4444
return cls(parent=parent, name=name)
4545

4646
def runtest(self):
47-
cur_dir = os.path.dirname(self.fspath)
47+
cur_dir = os.path.dirname(self.path)
4848

4949
# See https://bugs.python.org/issue37373
5050
if (
@@ -56,14 +56,14 @@ def runtest(self):
5656

5757
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
5858

59-
with self.fspath.open() as f:
59+
with self.path.open() as f:
6060
nb = nbformat.read(f, as_version=4)
6161
try:
6262
self.parent.exproc.preprocess(nb, {"metadata": {"path": cur_dir}})
6363
except CellExecutionError as e:
6464
raise NotebookException(e)
6565

66-
with open(self.fspath, "wt", encoding="utf-8") as f:
66+
with open(self.path, "wt", encoding="utf-8") as f:
6767
nbformat.write(nb, f)
6868

6969
def repr_failure(self, excinfo):
@@ -73,7 +73,7 @@ def repr_failure(self, excinfo):
7373
return super(NotebookItem, self).repr_failure((excinfo))
7474

7575
def reportinfo(self):
76-
return self.fspath, 0, "TestCase: %s" % self.name
76+
return self.path, 0, "TestCase: %s" % self.name
7777

7878

7979
class NotebookException(Exception):

0 commit comments

Comments
 (0)