Skip to content

Commit 301b494

Browse files
authored
fixes for dagster-cloud-action tests (#183)
* fixes for dagster-cloud-action tests Summary: - don't capture the output, that means we can't see what went wrong - don't fail if you can't remove the tempfile, just log - misc formatting * CentOS 7 fix
1 parent 2206ffe commit 301b494

File tree

4 files changed

+20
-28
lines changed

4 files changed

+20
-28
lines changed

generated/gha/dagster-cloud.pex

-7.14 MB
Binary file not shown.

scripts/release.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python3
2-
from contextlib import contextmanager
32
import glob
43
import os
5-
from pathlib import Path
64
import re
75
import shutil
86
import subprocess
97
import sys
8+
from contextlib import contextmanager
9+
from pathlib import Path
1010
from typing import List, Optional
1111

1212
import typer
@@ -47,7 +47,7 @@ def error(msg):
4747
@app.command()
4848
def run_tests():
4949
info("Running tests")
50-
subprocess.run(["pytest", "tests"], check=True)
50+
subprocess.run(["pytest", "tests", "-s"], check=True)
5151

5252

5353
@app.command(help="Build dagster-cloud-action docker image from dagster-cloud.pex")
@@ -179,9 +179,7 @@ def create_rc(
179179

180180

181181
def ensure_clean_workdir():
182-
proc = subprocess.run(
183-
["git", "status", "--porcelain"], capture_output=True, check=False
184-
)
182+
proc = subprocess.run(["git", "status", "--porcelain"], capture_output=True, check=False)
185183
if proc.stdout or proc.stderr:
186184
error("ERROR: Git working directory not clean:")
187185
error((proc.stdout + proc.stderr).decode("utf-8"))

src/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN /opt/python/cp38-cp38/bin/python -m pip install dagster-cloud-cli
99
RUN /opt/python/cp39-cp39/bin/python -m pip install dagster-cloud-cli
1010
RUN /opt/python/cp310-cp310/bin/python -m pip install dagster-cloud-cli
1111
RUN /opt/python/cp311-cp311/bin/python -m pip install dagster-cloud-cli
12+
RUN /opt/python/cp312-cp312/bin/python -m pip install dagster-cloud-cli
1213

1314
# Create virtual environment using PEX
1415
COPY generated/gha/dagster-cloud.pex /dagster-cloud.pex

tests/conftest.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import importlib
2+
import logging
23
import os
3-
import shutil
44
import subprocess
55
import sys
66
import tempfile
@@ -20,7 +20,7 @@ def __init__(self, tmp_dir):
2020
self.reset()
2121

2222
def tmp_file_path(self, filename) -> Path:
23-
"Return a Path object pointing to named file in tmp_dir."
23+
"""Return a Path object pointing to named file in tmp_dir."""
2424
return Path(self.tmp_dir) / filename
2525

2626
def tmp_file_content(self, filename):
@@ -42,7 +42,6 @@ def stub_command(self, cmdname, commands_map: Dict[str, str]):
4242
{'serverless registry-info --url "url" --api-token "token"':
4343
'AWS_ECR_USERNAME=username\nAWS_ECR_PASSWORD=password\n'})
4444
"""
45-
4645
command_stub.generate(str(self.tmp_file_path(cmdname)), commands_map)
4746

4847
def prepare_run_script(self, command: str, target_tmp_dir=None) -> Path:
@@ -72,13 +71,11 @@ def prepare_run_script(self, command: str, target_tmp_dir=None) -> Path:
7271
main_script.write("export PATH=.:$PATH\n")
7372

7473
# invoke main command
75-
main_script.write(
76-
command + " > ./output-stdout.txt 2> ./output-stderr.txt\n"
77-
)
74+
main_script.write(command + " > ./output-stdout.txt 2> ./output-stderr.txt\n")
7875

7976
# save returncode and final env vars
80-
main_script.write(f"echo $? > ./output-exitcode.txt\n")
81-
main_script.write(f"env > ./output-env.txt\n")
77+
main_script.write("echo $? > ./output-exitcode.txt\n")
78+
main_script.write("env > ./output-env.txt\n")
8279

8380
os.chmod(script_path, 0o700)
8481
return script_path
@@ -170,10 +167,10 @@ def repo_root():
170167

171168
@pytest.fixture(scope="session")
172169
def action_docker_image_id(repo_root):
173-
"Build a docker image using local source and return the tag"
170+
"""Build a docker image using local source and return the tag"""
174171
_, iidfile = tempfile.mkstemp()
175172
try:
176-
proc = subprocess.run(
173+
subprocess.run(
177174
[
178175
"docker",
179176
"buildx",
@@ -187,22 +184,24 @@ def action_docker_image_id(repo_root):
187184
],
188185
cwd=repo_root,
189186
check=True,
190-
capture_output=True,
191187
)
192188
return open(iidfile).read().strip()
193189
finally:
194-
os.remove(iidfile)
190+
try:
191+
os.remove(iidfile)
192+
except OSError:
193+
logging.exception(f"Failed to remove {iidfile}")
195194

196195

197196
@pytest.fixture(scope="session")
198197
def dagster_cloud_pex_path(repo_root):
199-
"Path to generated/gha/dagster-cloud.pex."
198+
"""Path to generated/gha/dagster-cloud.pex."""
200199
yield repo_root / "generated/gha/dagster-cloud.pex"
201200

202201

203202
@pytest.fixture(scope="session")
204203
def builder_module(dagster_cloud_pex_path):
205-
"Imported builder module object, for in-process testing of builder code."
204+
"""Imported builder module object, for in-process testing of builder code."""
206205
# This contains the same code as the builder.pex, but using it as a module
207206
# makes patching easier. To make sure we use the same dependencies that are
208207
# packed in builder.pex, we unpack builder.pex to a venv and add the venv
@@ -234,9 +233,7 @@ def pex_registry_fixture():
234233
s3_objects = {} # filename -> content
235234

236235
def s3_urls_for_get(filenames):
237-
return [
238-
(filename if filename in s3_objects else None) for filename in filenames
239-
]
236+
return [(filename if filename in s3_objects else None) for filename in filenames]
240237

241238
def s3_urls_for_put(filenames):
242239
return filenames
@@ -263,9 +260,5 @@ def requests_put(url, data):
263260
) as _, mock.patch(
264261
"dagster_cloud_cli.core.pex_builder.pex_registry.get_s3_urls_for_put",
265262
s3_urls_for_put,
266-
) as _, mock.patch(
267-
"requests.get", requests_get
268-
) as _, mock.patch(
269-
"requests.put", requests_put
270-
):
263+
) as _, mock.patch("requests.get", requests_get) as _, mock.patch("requests.put", requests_put):
271264
yield s3_objects

0 commit comments

Comments
 (0)