summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-01-03 06:30:43 -0500
committerNed Batchelder <ned@nedbatchelder.com>2023-01-03 06:44:38 -0500
commitc3ee30c1cfd133f1e36a4a8992b531a0dc7ec5a9 (patch)
treef97bb81c7bc66e9cccad8a28cf1e57d2ceeeb347
parent0b05b45e342813b34d906e840e253a06b37133ae (diff)
downloadpython-coveragepy-git-c3ee30c1cfd133f1e36a4a8992b531a0dc7ec5a9.tar.gz
refactor(test): use tmp_path instead of tmpdir
-rw-r--r--setup.cfg2
-rw-r--r--tests/balance_xdist_plugin.py3
-rw-r--r--tests/mixins.py6
-rw-r--r--tests/test_concurrency.py10
-rw-r--r--tests/test_python.py17
5 files changed, 21 insertions, 17 deletions
diff --git a/setup.cfg b/setup.cfg
index fd87eac4..adbdfb11 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -2,7 +2,7 @@
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
[tool:pytest]
-addopts = -q -n auto --strict-markers --no-flaky-report -rfEX --failed-first
+addopts = -q -n auto -p no:legacypath --strict-markers --no-flaky-report -rfEX --failed-first
python_classes = *Test
markers =
expensive: too slow to run during "make smoke"
diff --git a/tests/balance_xdist_plugin.py b/tests/balance_xdist_plugin.py
index 170037e6..aec7dc21 100644
--- a/tests/balance_xdist_plugin.py
+++ b/tests/balance_xdist_plugin.py
@@ -29,6 +29,7 @@ import csv
import os
import shutil
import time
+
from pathlib import Path
import pytest
@@ -64,7 +65,7 @@ class BalanceXdistPlugin: # pragma: debugging
if not self.running_all:
return
- tests_csv_dir = Path(session.startdir).resolve() / "tmp/tests_csv"
+ tests_csv_dir = session.startpath.resolve() / "tmp/tests_csv"
self.tests_csv = tests_csv_dir / f"{self.worker}.csv"
if self.worker == "none":
diff --git a/tests/mixins.py b/tests/mixins.py
index 7f246299..0f578637 100644
--- a/tests/mixins.py
+++ b/tests/mixins.py
@@ -12,7 +12,7 @@ import os
import os.path
import sys
-from typing import Tuple
+from typing import Iterator, Tuple
import pytest
@@ -57,10 +57,10 @@ class TempDirMixin:
run_in_temp_dir = True
@pytest.fixture(autouse=True)
- def _temp_dir(self, tmpdir_factory):
+ def _temp_dir(self, tmp_path_factory: pytest.TempPathFactory) -> Iterator[None]:
"""Create a temp dir for the tests, if they want it."""
if self.run_in_temp_dir:
- tmpdir = tmpdir_factory.mktemp("t")
+ tmpdir = tmp_path_factory.mktemp("t")
self.temp_dir = str(tmpdir)
with change_dir(self.temp_dir):
# Modules should be importable from this temp directory. We don't
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py
index b021d638..d08ed1ef 100644
--- a/tests/test_concurrency.py
+++ b/tests/test_concurrency.py
@@ -6,6 +6,7 @@
import glob
import multiprocessing
import os
+import pathlib
import random
import re
import sys
@@ -626,21 +627,22 @@ def test_coverage_stop_in_threads():
assert has_stopped_coverage == [t.ident]
-def test_thread_safe_save_data(tmpdir):
+def test_thread_safe_save_data(tmp_path: pathlib.Path) -> None:
# Non-regression test for: https://github.com/nedbat/coveragepy/issues/581
# Create some Python modules and put them in the path
- modules_dir = tmpdir.mkdir('test_modules')
+ modules_dir = tmp_path / "test_modules"
+ modules_dir.mkdir()
module_names = [f"m{i:03d}" for i in range(1000)]
for module_name in module_names:
- modules_dir.join(module_name + ".py").write("def f(): pass\n")
+ (modules_dir / (module_name + ".py")).write_text("def f(): pass\n")
# Shared variables for threads
should_run = [True]
imported = []
old_dir = os.getcwd()
- os.chdir(modules_dir.strpath)
+ os.chdir(modules_dir)
try:
# Make sure that all dummy modules can be imported.
for module_name in module_names:
diff --git a/tests/test_python.py b/tests/test_python.py
index fd8e7b52..c8c58f4e 100644
--- a/tests/test_python.py
+++ b/tests/test_python.py
@@ -3,6 +3,7 @@
"""Tests of coverage/python.py"""
+import pathlib
import sys
import pytest
@@ -37,9 +38,8 @@ class GetZipBytesTest(CoverageTest):
assert mod.encoding == encoding
-def test_source_for_file(tmpdir):
- path = tmpdir.join("a.py")
- src = str(path)
+def test_source_for_file(tmp_path: pathlib.Path) -> None:
+ src = str(tmp_path / "a.py")
assert source_for_file(src) == src
assert source_for_file(src + 'c') == src
assert source_for_file(src + 'o') == src
@@ -48,14 +48,15 @@ def test_source_for_file(tmpdir):
@pytest.mark.skipif(not env.WINDOWS, reason="not windows")
-def test_source_for_file_windows(tmpdir):
- path = tmpdir.join("a.py")
- src = str(path)
+def test_source_for_file_windows(tmp_path: pathlib.Path) -> None:
+ a_py = tmp_path / "a.py"
+ src = str(a_py)
# On windows if a pyw exists, it is an acceptable source
- path_windows = tmpdir.ensure("a.pyw")
+ path_windows = tmp_path / "a.pyw"
+ path_windows.write_text("")
assert str(path_windows) == source_for_file(src + 'c')
# If both pyw and py exist, py is preferred
- path.ensure(file=True)
+ a_py.write_text("")
assert source_for_file(src + 'c') == src