Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c3ee30c

Browse filesBrowse files
committed
refactor(test): use tmp_path instead of tmpdir
1 parent 0b05b45 commit c3ee30c
Copy full SHA for c3ee30c

File tree

5 files changed

+21
-17
lines changed
Filter options

5 files changed

+21
-17
lines changed

‎setup.cfg

Copy file name to clipboardExpand all lines: setup.cfg
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
33

44
[tool:pytest]
5-
addopts = -q -n auto --strict-markers --no-flaky-report -rfEX --failed-first
5+
addopts = -q -n auto -p no:legacypath --strict-markers --no-flaky-report -rfEX --failed-first
66
python_classes = *Test
77
markers =
88
expensive: too slow to run during "make smoke"

‎tests/balance_xdist_plugin.py

Copy file name to clipboardExpand all lines: tests/balance_xdist_plugin.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import os
3030
import shutil
3131
import time
32+
3233
from pathlib import Path
3334

3435
import pytest
@@ -64,7 +65,7 @@ def pytest_sessionstart(self, session):
6465
if not self.running_all:
6566
return
6667

67-
tests_csv_dir = Path(session.startdir).resolve() / "tmp/tests_csv"
68+
tests_csv_dir = session.startpath.resolve() / "tmp/tests_csv"
6869
self.tests_csv = tests_csv_dir / f"{self.worker}.csv"
6970

7071
if self.worker == "none":

‎tests/mixins.py

Copy file name to clipboardExpand all lines: tests/mixins.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os.path
1313
import sys
1414

15-
from typing import Tuple
15+
from typing import Iterator, Tuple
1616

1717
import pytest
1818

@@ -57,10 +57,10 @@ class TempDirMixin:
5757
run_in_temp_dir = True
5858

5959
@pytest.fixture(autouse=True)
60-
def _temp_dir(self, tmpdir_factory):
60+
def _temp_dir(self, tmp_path_factory: pytest.TempPathFactory) -> Iterator[None]:
6161
"""Create a temp dir for the tests, if they want it."""
6262
if self.run_in_temp_dir:
63-
tmpdir = tmpdir_factory.mktemp("t")
63+
tmpdir = tmp_path_factory.mktemp("t")
6464
self.temp_dir = str(tmpdir)
6565
with change_dir(self.temp_dir):
6666
# Modules should be importable from this temp directory. We don't

‎tests/test_concurrency.py

Copy file name to clipboardExpand all lines: tests/test_concurrency.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import glob
77
import multiprocessing
88
import os
9+
import pathlib
910
import random
1011
import re
1112
import sys
@@ -626,21 +627,22 @@ def run_thread(): # pragma: nested
626627
assert has_stopped_coverage == [t.ident]
627628

628629

629-
def test_thread_safe_save_data(tmpdir):
630+
def test_thread_safe_save_data(tmp_path: pathlib.Path) -> None:
630631
# Non-regression test for: https://github.com/nedbat/coveragepy/issues/581
631632

632633
# Create some Python modules and put them in the path
633-
modules_dir = tmpdir.mkdir('test_modules')
634+
modules_dir = tmp_path / "test_modules"
635+
modules_dir.mkdir()
634636
module_names = [f"m{i:03d}" for i in range(1000)]
635637
for module_name in module_names:
636-
modules_dir.join(module_name + ".py").write("def f(): pass\n")
638+
(modules_dir / (module_name + ".py")).write_text("def f(): pass\n")
637639

638640
# Shared variables for threads
639641
should_run = [True]
640642
imported = []
641643

642644
old_dir = os.getcwd()
643-
os.chdir(modules_dir.strpath)
645+
os.chdir(modules_dir)
644646
try:
645647
# Make sure that all dummy modules can be imported.
646648
for module_name in module_names:

‎tests/test_python.py

Copy file name to clipboardExpand all lines: tests/test_python.py
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Tests of coverage/python.py"""
55

6+
import pathlib
67
import sys
78

89
import pytest
@@ -37,9 +38,8 @@ def test_get_encoded_zip_files(self, encoding):
3738
assert mod.encoding == encoding
3839

3940

40-
def test_source_for_file(tmpdir):
41-
path = tmpdir.join("a.py")
42-
src = str(path)
41+
def test_source_for_file(tmp_path: pathlib.Path) -> None:
42+
src = str(tmp_path / "a.py")
4343
assert source_for_file(src) == src
4444
assert source_for_file(src + 'c') == src
4545
assert source_for_file(src + 'o') == src
@@ -48,14 +48,15 @@ def test_source_for_file(tmpdir):
4848

4949

5050
@pytest.mark.skipif(not env.WINDOWS, reason="not windows")
51-
def test_source_for_file_windows(tmpdir):
52-
path = tmpdir.join("a.py")
53-
src = str(path)
51+
def test_source_for_file_windows(tmp_path: pathlib.Path) -> None:
52+
a_py = tmp_path / "a.py"
53+
src = str(a_py)
5454

5555
# On windows if a pyw exists, it is an acceptable source
56-
path_windows = tmpdir.ensure("a.pyw")
56+
path_windows = tmp_path / "a.pyw"
57+
path_windows.write_text("")
5758
assert str(path_windows) == source_for_file(src + 'c')
5859

5960
# If both pyw and py exist, py is preferred
60-
path.ensure(file=True)
61+
a_py.write_text("")
6162
assert source_for_file(src + 'c') == src

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.