Skip to content

Commit e264e86

Browse files
authored
Merge pull request #538 from py-cov-action/fix-ci
2 parents 372a70d + d4c84a3 commit e264e86

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

coverage_comment/main.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@ def main():
3333
log.info("Starting action")
3434
config = settings.Config.from_environ(environ=os.environ)
3535

36-
github_session = httpx.Client(
37-
base_url=config.GITHUB_BASE_URL,
38-
follow_redirects=True,
39-
headers={"Authorization": f"token {config.GITHUB_TOKEN}"},
40-
)
41-
http_session = httpx.Client()
4236
git = subprocess.Git()
4337

44-
exit_code = action(
45-
config=config,
46-
github_session=github_session,
47-
http_session=http_session,
48-
git=git,
49-
)
38+
with (
39+
httpx.Client(
40+
base_url=config.GITHUB_BASE_URL,
41+
follow_redirects=True,
42+
headers={"Authorization": f"token {config.GITHUB_TOKEN}"},
43+
) as github_session,
44+
httpx.Client() as http_session,
45+
):
46+
exit_code = action(
47+
config=config,
48+
github_session=github_session,
49+
http_session=http_session,
50+
git=git,
51+
)
5052

5153
log.info("Ending action")
5254
sys.exit(exit_code)

tests/end_to_end/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import subprocess
1212
import time
1313

14+
import httpx
1415
import pytest
1516
import tenacity
1617

@@ -387,3 +388,9 @@ def f(line):
387388
git("commit", "-m", "improve coverage")
388389

389390
return f
391+
392+
393+
@pytest.fixture
394+
def http_client():
395+
with httpx.Client() as client:
396+
yield client

tests/end_to_end/test_all.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import base64
44

5-
import httpx
65
import pytest
76

87

@@ -24,6 +23,7 @@ def test_public_repo(
2423
token_other,
2524
gh_create_fork,
2625
gh_other_username,
26+
http_client,
2727
):
2828
# Create a GitHub repo, make it public
2929
gh_create_repo("--public")
@@ -60,14 +60,12 @@ def test_public_repo(
6060
# - coverage branch readme url
6161
assert len(links) == 5
6262

63-
client = httpx.Client()
64-
6563
# Check that all 5 links are valid and lead to a 200
6664
# It's made this way to avoid hardcoding links in the test, because I assume
6765
# they'll be evolving.
6866
number_of_svgs = 0
6967
for link in links:
70-
response = client.get(link)
68+
response = http_client.get(link)
7169
response.raise_for_status()
7270
number_of_svgs += int(response.text.startswith("<svg"))
7371

@@ -81,7 +79,7 @@ def test_public_repo(
8179
raw_url_prefix = f"https://github.com/{repo_full_name}/raw/python-coverage-comment-action-data-my-great-project"
8280

8381
readme_url = f"{raw_url_prefix}/README.md"
84-
response = client.get(readme_url, follow_redirects=True)
82+
response = http_client.get(readme_url, follow_redirects=True)
8583
response.raise_for_status()
8684
# And all previously found links should be present
8785
readme = response.text
@@ -91,13 +89,13 @@ def test_public_repo(
9189
# And while we're at it, there are 2 other files we want to check in this
9290
# branch. Once again, trying to avoid hardcoding too many specifics, that's what
9391
# unit tests are for.
94-
data = client.get(f"{raw_url_prefix}/data.json", follow_redirects=True).json()
92+
data = http_client.get(f"{raw_url_prefix}/data.json", follow_redirects=True).json()
9593
assert "coverage" in data
9694
assert "raw_data" in data
9795
assert "meta" in data["raw_data"]
9896
assert "coverage_path" in data
9997

100-
endpoint = client.get(
98+
endpoint = http_client.get(
10199
f"{raw_url_prefix}/endpoint.json", follow_redirects=True
102100
).json()
103101
assert "schemaVersion" in endpoint

0 commit comments

Comments
 (0)