Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pytest=8 #1330

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ build
conda-lock
pre-commit
pytest-cov
pytest>=4.6
pytest>=7
pyyaml
requests_mock
29 changes: 14 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
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)
elif path.basename.endswith(".repos.yaml"):
return RemoteRepoList.from_parent(parent, fspath=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):
Expand Down Expand Up @@ -213,7 +213,7 @@ def __init__(
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
Expand All @@ -233,24 +233,23 @@ def collect(self):
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")
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.fspath.basename, self.fspath.dirname, str(self.fspath))
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.fspath.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.fspath.dirname)
args.append(str(self.path.parent))
yield Repo2DockerTest.from_parent(self, name="build", args=args)

yield Repo2DockerTest.from_parent(
self,
name=self.fspath.basename,
name=self.path.name,
args=args + ["./verify"],
skip_build=True,
)
Expand All @@ -273,7 +272,7 @@ def collect(self):

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 = []
Expand Down
Loading