Skip to content

Commit

Permalink
Run 1/2 of e2e tests in a subdir (src subfolder)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Jul 26, 2023
1 parent f7cde42 commit 5102eb3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ filterwarnings =
error
markers=
repo_suffix: Allows to use an additional suffix for the e2e test repo.
code_path: Allows to place the code in a subdirectory for the e2e test repo.
32 changes: 25 additions & 7 deletions tests/end_to_end/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _(command, *args, env, **kwargs):
@contextlib.contextmanager
def _cd(tmp_path: pathlib.Path, path: str):
full_path = tmp_path / path
full_path.mkdir(exist_ok=True)
full_path.mkdir(exist_ok=True, parents=True)
old_path = pathlib.Path.cwd()
if old_path == full_path:
yield full_path
Expand Down Expand Up @@ -191,18 +191,30 @@ def gh_other_username(gh_other):


@pytest.fixture
def git_repo(cd, git, action_ref):
def git_repo(cd, git, action_ref, code_path):
with cd("repo") as repo:
git("init", "-b", "main")
# Copy .github
shutil.copytree(
pathlib.Path(__file__).parent / "repo" / ".github",
repo / ".github",
dirs_exist_ok=True,
)
# Copy everything else
shutil.copytree(
pathlib.Path(__file__).parent / "repo",
repo,
repo / code_path,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns(".github"),
)
# Rewrite the specific version of the action we run in the workflow files.
for file in (repo / ".github/workflows").iterdir():
file: pathlib.Path
file.write_text(file.read_text().replace("__ACTION_REF__", action_ref))
content = (
file.read_text()
.replace("__ACTION_REF__", action_ref)
.replace("__ACTION_COVERAGE_PATH__", str(code_path))
)
file.write_text(content)

git("add", ".")
git("commit", "-m", "initial commit")
Expand All @@ -221,6 +233,12 @@ def repo_name(request):
return name


@pytest.fixture
def code_path(request):
mark = request.node.get_closest_marker("code_path")
return pathlib.Path(*mark.args) if mark else pathlib.Path(".")


@pytest.fixture
def repo_full_name(repo_name, gh_me_username):
return f"{gh_me_username}/{repo_name}"
Expand Down Expand Up @@ -378,9 +396,9 @@ def _(*, workflow_name, triggering_user, gh):


@pytest.fixture
def add_coverage_line(git):
def add_coverage_line(git, code_path):
def f(line):
csv_file = pathlib.Path("tests/cases.csv")
csv_file = pathlib.Path(code_path / "tests/cases.csv")
csv_file.write_text(csv_file.read_text() + line + "\n")

git("add", str(csv_file))
Expand Down
10 changes: 6 additions & 4 deletions tests/end_to_end/repo/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
push:
branches:
- 'main'
- "main"

concurrency:
group: CI
Expand All @@ -17,20 +17,21 @@ jobs:
pull-requests: write
contents: write
steps:

- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'poetry'
python-version: "3.10"
cache: "poetry"

- run: poetry install
working-directory: __ACTION_COVERAGE_PATH__

- run: poetry run pytest
working-directory: __ACTION_COVERAGE_PATH__

- name: Coverage comment
id: coverage_comment
Expand All @@ -39,6 +40,7 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
ANNOTATE_MISSING_LINES: true
ANNOTATION_TYPE: notice
COVERAGE_PATH: __ACTION_COVERAGE_PATH__

- name: Store Pull Request comment to be posted
uses: actions/upload-artifact@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ jobs:
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
COVERAGE_PATH: __ACTION_COVERAGE_PATH__
3 changes: 2 additions & 1 deletion tests/end_to_end/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


@pytest.mark.repo_suffix("public")
@pytest.mark.code_path("subdir")
def test_public_repo(
gh_create_repo,
wait_for_run_to_start,
Expand All @@ -28,7 +29,7 @@ def test_public_repo(
run_id = wait_for_run_to_start(sha1=get_sha1(), branch="main", gh=gh_me)

# AAAaand it's started. Now let's wait for it to end.
# Also, raise if it doesn't end succefully. That half of the job.
# Also, raise if it doesn't end successfully. That half of the job.
gh_me("run", "watch", run_id, "--exit-status")

# Now to the other half: maybe it did nothing successfully, so let's check
Expand Down

0 comments on commit 5102eb3

Please sign in to comment.