pytest: replace fspath with path

pull/1330/head
Simon Li 2024-01-28 18:04:51 +00:00
rodzic 3505ad7c8b
commit 6fe9ee6763
1 zmienionych plików z 9 dodań i 9 usunięć

Wyświetl plik

@ -35,9 +35,9 @@ TESTS_DIR = os.path.abspath(os.path.dirname(__file__))
def pytest_collect_file(parent, path): def pytest_collect_file(parent, path):
if path.basename == "verify": if path.basename == "verify":
return LocalRepo.from_parent(parent, fspath=path) return LocalRepo.from_parent(parent, path=path)
elif path.basename.endswith(".repos.yaml"): 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): 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) super().__init__(name, parent, callobj=f)
def reportinfo(self): def reportinfo(self):
return (self.parent.fspath, None, "") return (self.parent.path, None, "")
def repr_failure(self, excinfo): def repr_failure(self, excinfo):
err = excinfo.value err = excinfo.value
@ -233,24 +233,24 @@ class LocalRepo(pytest.File):
args = ["--appendix", 'RUN echo "appendix" > /tmp/appendix'] args = ["--appendix", 'RUN echo "appendix" > /tmp/appendix']
# If there's an extra-args.yaml file in a test dir, assume it contains # 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 # 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): if os.path.exists(extra_args_path):
with open(extra_args_path) as f: with open(extra_args_path) as f:
extra_args = yaml.safe_load(f) extra_args = yaml.safe_load(f)
args += extra_args 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 # re-use image name for multiple tests of the same image
# so we don't run through the build twice # 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())}" 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(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="build", args=args)
yield Repo2DockerTest.from_parent( yield Repo2DockerTest.from_parent(
self, self,
name=self.fspath.basename, name=self.path.basename,
args=args + ["./verify"], args=args + ["./verify"],
skip_build=True, skip_build=True,
) )
@ -273,7 +273,7 @@ class LocalRepo(pytest.File):
class RemoteRepoList(pytest.File): class RemoteRepoList(pytest.File):
def collect(self): def collect(self):
with self.fspath.open() as f: with self.path.open() as f:
repos = yaml.safe_load(f) repos = yaml.safe_load(f)
for repo in repos: for repo in repos:
args = [] args = []