diff --git a/setup.cfg b/setup.cfg index fd87eac46..adbdfb11a 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 170037e6b..aec7dc21c 100644 --- a/tests/balance_xdist_plugin.py +++ b/tests/balance_xdist_plugin.py @@ -29,6 +29,7 @@ import os import shutil import time + from pathlib import Path import pytest @@ -64,7 +65,7 @@ def pytest_sessionstart(self, session): 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 7f2462998..0f578637d 100644 --- a/tests/mixins.py +++ b/tests/mixins.py @@ -12,7 +12,7 @@ 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 b021d638b..d08ed1efb 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 run_thread(): # pragma: nested 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 fd8e7b523..c8c58f4ef 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 @@ def test_get_encoded_zip_files(self, encoding): 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