From 3505ad7c8b4e0aaf3025f0f38400ffea2dff9e2c Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 28 Jan 2024 17:00:51 +0000 Subject: [PATCH 1/4] Pin pytest<8 --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 6553a674..c2b8cf1d 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,6 +2,6 @@ build conda-lock pre-commit pytest-cov -pytest>=4.6 +pytest>=4.6,<8 pyyaml requests_mock From 6fe9ee6763b5cad313a07dd01da97cb9799c5aba Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 28 Jan 2024 18:04:51 +0000 Subject: [PATCH 2/4] pytest: replace fspath with path --- tests/conftest.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 87cccb8b..333d0b24 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,9 +35,9 @@ TESTS_DIR = os.path.abspath(os.path.dirname(__file__)) def pytest_collect_file(parent, path): if path.basename == "verify": - return LocalRepo.from_parent(parent, fspath=path) + return LocalRepo.from_parent(parent, path=path) elif path.basename.endswith(".repos.yaml"): - return RemoteRepoList.from_parent(parent, fspath=path) + return RemoteRepoList.from_parent(parent, path=path) def make_test_func(args, skip_build=False, extra_run_kwargs=None): @@ -213,7 +213,7 @@ class Repo2DockerTest(pytest.Function): super().__init__(name, parent, callobj=f) def reportinfo(self): - return (self.parent.fspath, None, "") + return (self.parent.path, None, "") def repr_failure(self, excinfo): err = excinfo.value @@ -233,24 +233,24 @@ class LocalRepo(pytest.File): args = ["--appendix", 'RUN echo "appendix" > /tmp/appendix'] # If there's an extra-args.yaml file in a test dir, assume it contains # a yaml list with extra arguments to be passed to repo2docker - extra_args_path = os.path.join(self.fspath.dirname, "test-extra-args.yaml") + extra_args_path = os.path.join(self.path.dirname, "test-extra-args.yaml") if os.path.exists(extra_args_path): with open(extra_args_path) as f: extra_args = yaml.safe_load(f) args += extra_args - print(self.fspath.basename, self.fspath.dirname, str(self.fspath)) + print(self.path.basename, self.path.dirname, str(self.path)) # re-use image name for multiple tests of the same image # so we don't run through the build twice - rel_repo_dir = os.path.relpath(self.fspath.dirname, TESTS_DIR) + rel_repo_dir = os.path.relpath(self.path.dirname, TESTS_DIR) image_name = f"r2d-tests-{escapism.escape(rel_repo_dir, escape_char='-').lower()}-{int(time.time())}" args.append(f"--image-name={image_name}") - args.append(self.fspath.dirname) + args.append(self.path.dirname) yield Repo2DockerTest.from_parent(self, name="build", args=args) yield Repo2DockerTest.from_parent( self, - name=self.fspath.basename, + name=self.path.basename, args=args + ["./verify"], skip_build=True, ) @@ -273,7 +273,7 @@ class LocalRepo(pytest.File): class RemoteRepoList(pytest.File): def collect(self): - with self.fspath.open() as f: + with self.path.open() as f: repos = yaml.safe_load(f) for repo in repos: args = [] From 237375f3a490ba0ff6d9a46850a722649883bfb7 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 28 Jan 2024 19:26:24 +0000 Subject: [PATCH 3/4] pytest >=7,<9 --- dev-requirements.txt | 2 +- tests/conftest.py | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index c2b8cf1d..f7d64cc7 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,6 +2,6 @@ build conda-lock pre-commit pytest-cov -pytest>=4.6,<8 +pytest>=7,<9 pyyaml requests_mock diff --git a/tests/conftest.py b/tests/conftest.py index 333d0b24..76f14c80 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,11 +33,11 @@ from repo2docker.__main__ import make_r2d TESTS_DIR = os.path.abspath(os.path.dirname(__file__)) -def pytest_collect_file(parent, path): - if path.basename == "verify": - return LocalRepo.from_parent(parent, path=path) - elif path.basename.endswith(".repos.yaml"): - return RemoteRepoList.from_parent(parent, path=path) +def pytest_collect_file(parent, file_path): + if file_path.name == "verify": + return LocalRepo.from_parent(parent, path=file_path) + elif file_path.name.endswith(".repos.yaml"): + return RemoteRepoList.from_parent(parent, path=file_path) def make_test_func(args, skip_build=False, extra_run_kwargs=None): @@ -233,24 +233,23 @@ class LocalRepo(pytest.File): args = ["--appendix", 'RUN echo "appendix" > /tmp/appendix'] # If there's an extra-args.yaml file in a test dir, assume it contains # a yaml list with extra arguments to be passed to repo2docker - extra_args_path = os.path.join(self.path.dirname, "test-extra-args.yaml") - if os.path.exists(extra_args_path): - with open(extra_args_path) as f: - extra_args = yaml.safe_load(f) + extra_args_path = self.path.parent / "test-extra-args.yaml" + if extra_args_path.exists(): + extra_args = yaml.safe_load(extra_args_path.read_text()) args += extra_args - print(self.path.basename, self.path.dirname, str(self.path)) + print(self.path.name, self.path.parent, str(self.path)) # re-use image name for multiple tests of the same image # so we don't run through the build twice - rel_repo_dir = os.path.relpath(self.path.dirname, TESTS_DIR) + rel_repo_dir = os.path.relpath(self.path.parent, TESTS_DIR) image_name = f"r2d-tests-{escapism.escape(rel_repo_dir, escape_char='-').lower()}-{int(time.time())}" args.append(f"--image-name={image_name}") - args.append(self.path.dirname) + args.append(str(self.path.parent)) yield Repo2DockerTest.from_parent(self, name="build", args=args) yield Repo2DockerTest.from_parent( self, - name=self.path.basename, + name=self.path.name, args=args + ["./verify"], skip_build=True, ) From 56299a2312762c07e16648a346f2c144df6b0d9a Mon Sep 17 00:00:00 2001 From: Simon Li Date: Thu, 1 Feb 2024 22:39:08 +0000 Subject: [PATCH 4/4] Don't pin upper pytest version --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index f7d64cc7..22ba622e 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,6 +2,6 @@ build conda-lock pre-commit pytest-cov -pytest>=7,<9 +pytest>=7 pyyaml requests_mock