Skip to content

Commit

Permalink
Fix notebook tests and improve their output
Browse files Browse the repository at this point in the history
  • Loading branch information
tkilias committed Mar 7, 2024
1 parent a414b2c commit 515ff6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion test/docker/exec_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def handle_output(output: Union[bytes, Iterator[bytes]], print_output: bool):
output_string = None
if print_output and isinstance(output, Iterator):
for chunk in output:
print(decode_bytes(chunk))
print(decode_bytes(chunk), flush=True)
else:
output_string = decode_bytes(output)
return output_string
Expand Down
31 changes: 14 additions & 17 deletions test/notebook_test_runner/test_notebooks_in_dss_docker_image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import os
import time
from inspect import cleandoc
from pathlib import Path

Expand All @@ -19,12 +20,11 @@ def notebook_test_dockerfile_content(dss_docker_image) -> str:
f"""
FROM {dss_docker_image.image_name}
COPY notebooks/* /tmp/notebooks/
USER ubuntu
RUN sudo mv /tmp/notebooks/* "$NOTEBOOK_FOLDER_INITIAL" && sudo rmdir /tmp/notebooks/
RUN sudo chown -R jupyter "$NOTEBOOK_FOLDER_INITIAL"
USER jupyter
RUN sudo chown -R jupyter:jupyter "$NOTEBOOK_FOLDER_INITIAL"
WORKDIR $NOTEBOOK_FOLDER_INITIAL
RUN "$VIRTUAL_ENV/bin/python3" -m pip install -r test_dependencies.txt
RUN sudo "$VIRTUAL_ENV/bin/python3" -m pip install -r test_dependencies.txt
RUN sudo chown -R jupyter:jupyter "$VIRTUAL_ENV"
"""
)

Expand All @@ -48,17 +48,14 @@ def notebook_test_image(request, notebook_test_build_context):

@pytest.fixture()
def notebook_test_container(request, notebook_test_image):
yield from container(
request,
base_name="notebook_test_container",
image=notebook_test_image,
volumes={
'/var/run/docker.sock': {
'bind': '/var/run/docker.sock',
'mode': 'rw',
},
},
)
container_obj = container(request, base_name="notebook_test_container", image=notebook_test_image,
volumes={'/var/run/docker.sock': {
'bind': '/var/run/docker.sock',
'mode': 'rw', }, }, )
time.sleep(2) # wait that the entrypoint changed the permissions of the docker socket
print("Container Logs:")
print(container_obj.logs().decode("utf-8"), flush=True)
yield from container_obj


def ignored_warnings():
Expand All @@ -70,7 +67,7 @@ def ignored_warnings():
]
}
args = ""
for category,messages in warnings.items():
for category, messages in warnings.items():
for m in messages:
args += f' -W "ignore:{m}:{category}"'
return args
Expand All @@ -96,4 +93,4 @@ def test_notebook(notebook_test_container, notebook_test_file):
environ = os.environ.copy()
environ["NBTEST_ACTIVE"] = "TRUE"
nbtest_environ = {key: value for key, value in environ.items() if key.startswith("NBTEST_")}
exec_command(command_run_test, container, print_output=True, environment=nbtest_environ)
exec_command(command_run_test, container, print_output=True, environment=nbtest_environ, user="jupyter")

0 comments on commit 515ff6e

Please sign in to comment.