From 3231d6c20e62e36e284d743896334fca114a8efa Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Wed, 26 Jul 2023 19:21:22 +0200 Subject: [PATCH] Run 1/2 of e2e tests in a subdir (src subfolder) --- setup.cfg | 1 + tests/end_to_end/conftest.py | 36 ++++++++++++++----- .../end_to_end/repo/.github/workflows/ci.yml | 8 ++--- .../.github/workflows/coverage-comment.yml | 1 + tests/end_to_end/test_all.py | 3 +- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/setup.cfg b/setup.cfg index adf8c25d..42de93f1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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. diff --git a/tests/end_to_end/conftest.py b/tests/end_to_end/conftest.py index 50ee5087..3af27868 100644 --- a/tests/end_to_end/conftest.py +++ b/tests/end_to_end/conftest.py @@ -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 @@ -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 @@ -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", @@ -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 or ".") + ) + file.write_text(content) git("add", ".") git("commit", "-m", "initial commit") @@ -221,6 +225,22 @@ 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): + return f"{code_path}/{folder}" if code_path else folder + + return f + + @pytest.fixture def repo_full_name(repo_name, gh_me_username): return f"{gh_me_username}/{repo_name}" diff --git a/tests/end_to_end/repo/.github/workflows/ci.yml b/tests/end_to_end/repo/.github/workflows/ci.yml index dbdc8bb8..4505eb87 100644 --- a/tests/end_to_end/repo/.github/workflows/ci.yml +++ b/tests/end_to_end/repo/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - 'main' + - "main" concurrency: group: CI @@ -17,7 +17,6 @@ jobs: pull-requests: write contents: write steps: - - uses: actions/checkout@v3 - name: Install poetry @@ -25,8 +24,8 @@ jobs: - uses: actions/setup-python@v4 with: - python-version: '3.10' - cache: 'poetry' + python-version: "3.10" + cache: "poetry" - run: poetry install @@ -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 diff --git a/tests/end_to_end/repo/.github/workflows/coverage-comment.yml b/tests/end_to_end/repo/.github/workflows/coverage-comment.yml index af0387de..9db6642d 100644 --- a/tests/end_to_end/repo/.github/workflows/coverage-comment.yml +++ b/tests/end_to_end/repo/.github/workflows/coverage-comment.yml @@ -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__ diff --git a/tests/end_to_end/test_all.py b/tests/end_to_end/test_all.py index 81482cb0..5944cb43 100644 --- a/tests/end_to_end/test_all.py +++ b/tests/end_to_end/test_all.py @@ -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, @@ -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