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 8505bd0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 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.
37 changes: 29 additions & 8 deletions tests/end_to_end/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def f(*args, env=None):


@pytest.fixture
def gh_me(gh, cd, token_me):
def gh_me(gh, cd, token_me, code_fullpath):
def f(*args, **kwargs):
with cd("repo"):
with cd(code_fullpath("repo")):
return gh(*args, token=token_me, **kwargs)

return f
Expand All @@ -177,9 +177,9 @@ def gh_me_username(gh_me):


@pytest.fixture
def gh_other(gh, cd, token_other):
def gh_other(gh, cd, token_other, code_fullpath):
def f(*args, **kwargs):
with cd("fork"):
with cd(code_fullpath("fork")):
return gh(*args, token=token_other, **kwargs)

return f
Expand All @@ -191,8 +191,8 @@ def gh_other_username(gh_other):


@pytest.fixture
def git_repo(cd, git, action_ref):
with cd("repo") as repo:
def git_repo(cd, git, action_ref, code_fullpath, code_path):
with cd(code_fullpath("repo")) as repo:
git("init", "-b", "main")
shutil.copytree(
pathlib.Path(__file__).parent / "repo",
Expand All @@ -201,8 +201,12 @@ def git_repo(cd, git, action_ref):
)
# 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__", code_path)
)
file.write_text(content)

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


@pytest.fixture
def code_path(request):
mark = request.node.get_closest_marker("code_path")
if not mark:
return None
return "/".join(mark.args)


@pytest.fixture
def code_fullpath(code_path):
def f(folder):
parts = [folder, *(code_path or [])]
return "/".join(parts)

return f


@pytest.fixture
def repo_full_name(repo_name, gh_me_username):
return f"{gh_me_username}/{repo_name}"
Expand Down
8 changes: 4 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,16 +17,15 @@ 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

Expand All @@ -39,6 +38,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("src")
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 8505bd0

Please sign in to comment.