Do not allocate TTY in tests if not needed (#2257)

This commit is contained in:
Ayaz Salikhov
2025-03-21 12:15:16 +00:00
committed by GitHub
parent f0ef7e30b2
commit 95aa99dd85
18 changed files with 3 additions and 47 deletions

View File

@@ -33,7 +33,6 @@ def test_nbconvert(container: TrackedContainer, test_file: str) -> None:
timeout=60,
no_warnings=False,
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
tty=True,
command=["bash", "-c", command],
)
warnings = TrackedContainer.get_warnings(logs)

View File

@@ -33,7 +33,6 @@ def test_nb_user_change(container: TrackedContainer) -> None:
"""Container should change the username (`NB_USER`) of the default user."""
nb_user = "nayvoj"
container.run_detached(
tty=True,
user="root",
environment=[f"NB_USER={nb_user}", "CHOWN_HOME=yes"],
command=["bash", "-c", "sleep infinity"],

View File

@@ -17,7 +17,6 @@ def get_healthy_status(
user: str | None,
) -> str:
container.run_detached(
tty=True,
environment=env,
command=cmd,
user=user,

View File

@@ -41,6 +41,5 @@ def test_ipv46(container: TrackedContainer, ipv6_network: str) -> None:
container.run_detached(
network=ipv6_network,
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro,z"}},
tty=True,
)
container.exec_cmd(f"python {cont_data_dir}/check_listening.py")

View File

@@ -11,7 +11,6 @@ def test_pandoc(container: TrackedContainer) -> None:
"""Pandoc shall be able to convert MD to HTML."""
logs = container.run_and_wait(
timeout=10,
tty=True,
command=["bash", "-c", 'echo "**BOLD**" | pandoc'],
)
assert "<p><strong>BOLD</strong></p>" in logs

View File

@@ -76,7 +76,7 @@ def test_tini_entrypoint(
https://superuser.com/questions/632979/if-i-know-the-pid-number-of-a-process-how-can-i-get-its-name
"""
LOGGER.info(f"Test that {command} is launched as PID {pid} ...")
container.run_detached(tty=True)
container.run_detached()
# Select the PID 1 and get the corresponding command
output = container.exec_cmd(f"ps -p {pid} -o comm=")
assert "ERROR" not in output

View File

@@ -14,7 +14,6 @@ def test_python_version(container: TrackedContainer) -> None:
)
logs = container.run_and_wait(
timeout=5,
tty=True,
command=["python", "--version"],
)
python = next(line for line in logs.splitlines() if line.startswith("Python "))
@@ -28,7 +27,6 @@ def test_python_pinned_version(container: TrackedContainer) -> None:
LOGGER.info(f"Checking that pinned python version is {EXPECTED_PYTHON_VERSION}.*")
logs = container.run_and_wait(
timeout=5,
tty=True,
command=["cat", "/opt/conda/conda-meta/pinned"],
)
assert f"python {EXPECTED_PYTHON_VERSION}.*" in logs

View File

@@ -12,7 +12,6 @@ THIS_DIR = Path(__file__).parent.resolve()
def test_run_hooks_zero_args(container: TrackedContainer) -> None:
logs = container.run_and_wait(
timeout=5,
tty=True,
no_failure=False,
command=["bash", "-c", "source /usr/local/bin/run-hooks.sh"],
)
@@ -22,7 +21,6 @@ def test_run_hooks_zero_args(container: TrackedContainer) -> None:
def test_run_hooks_two_args(container: TrackedContainer) -> None:
logs = container.run_and_wait(
timeout=5,
tty=True,
no_failure=False,
command=[
"bash",
@@ -36,7 +34,6 @@ def test_run_hooks_two_args(container: TrackedContainer) -> None:
def test_run_hooks_missing_dir(container: TrackedContainer) -> None:
logs = container.run_and_wait(
timeout=5,
tty=True,
no_failure=False,
command=[
"bash",
@@ -50,7 +47,6 @@ def test_run_hooks_missing_dir(container: TrackedContainer) -> None:
def test_run_hooks_dir_is_file(container: TrackedContainer) -> None:
logs = container.run_and_wait(
timeout=5,
tty=True,
no_failure=False,
command=[
"bash",
@@ -64,7 +60,6 @@ def test_run_hooks_dir_is_file(container: TrackedContainer) -> None:
def test_run_hooks_empty_dir(container: TrackedContainer) -> None:
container.run_and_wait(
timeout=5,
tty=True,
command=[
"bash",
"-c",
@@ -91,7 +86,6 @@ def run_source_in_dir(
return container.run_and_wait(
timeout=5,
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
tty=True,
no_failure=no_failure,
command=["bash", "-c", command],
)

View File

@@ -33,6 +33,5 @@ def test_units(container: TrackedContainer) -> None:
container.run_and_wait(
timeout=30,
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
tty=True,
command=["python", f"{cont_data_dir}/{test_file_name}"],
)

View File

@@ -15,7 +15,6 @@ def test_uid_change(container: TrackedContainer) -> None:
"""Container should change the UID of the default user."""
logs = container.run_and_wait(
timeout=120, # usermod is slow so give it some time
tty=True,
user="root",
environment=["NB_UID=1010"],
command=["bash", "-c", "id && touch /opt/conda/test-file"],
@@ -27,7 +26,6 @@ def test_gid_change(container: TrackedContainer) -> None:
"""Container should change the GID of the default user."""
logs = container.run_and_wait(
timeout=10,
tty=True,
user="root",
environment=["NB_GID=110"],
command=["id"],
@@ -40,7 +38,6 @@ def test_nb_user_change(container: TrackedContainer) -> None:
"""Container should change the username (`NB_USER`) of the default user."""
nb_user = "nayvoj"
container.run_detached(
tty=True,
user="root",
environment=[f"NB_USER={nb_user}", "CHOWN_HOME=yes"],
command=["bash", "-c", "sleep infinity"],
@@ -87,7 +84,6 @@ def test_chown_extra(container: TrackedContainer) -> None:
CHOWN_EXTRA list of folders."""
logs = container.run_and_wait(
timeout=120, # chown is slow so give it some time
tty=True,
user="root",
environment=[
"NB_UID=1010",
@@ -110,7 +106,6 @@ def test_chown_home(container: TrackedContainer) -> None:
group to the current value of NB_UID and NB_GID."""
logs = container.run_and_wait(
timeout=120, # chown is slow so give it some time
tty=True,
user="root",
environment=[
"CHOWN_HOME=yes",
@@ -128,7 +123,6 @@ def test_sudo(container: TrackedContainer) -> None:
"""Container should grant passwordless sudo to the default user."""
logs = container.run_and_wait(
timeout=10,
tty=True,
user="root",
environment=["GRANT_SUDO=yes"],
command=["sudo", "id"],
@@ -140,7 +134,6 @@ def test_sudo_path(container: TrackedContainer) -> None:
"""Container should include /opt/conda/bin in the sudo secure_path."""
logs = container.run_and_wait(
timeout=10,
tty=True,
user="root",
environment=["GRANT_SUDO=yes"],
command=["sudo", "which", "jupyter"],
@@ -152,7 +145,6 @@ def test_sudo_path_without_grant(container: TrackedContainer) -> None:
"""Container should include /opt/conda/bin in the sudo secure_path."""
logs = container.run_and_wait(
timeout=10,
tty=True,
user="root",
command=["which", "jupyter"],
)
@@ -224,7 +216,6 @@ def test_container_not_delete_bind_mount(
container.run_and_wait(
timeout=5,
tty=True,
user="root",
working_dir="/home/",
environment=[
@@ -247,7 +238,6 @@ def test_jupyter_env_vars_to_unset(
root_args = {"user": "root"} if enable_root else {}
logs = container.run_and_wait(
timeout=10,
tty=True,
environment=[
"JUPYTER_ENV_VARS_TO_UNSET=SECRET_ANIMAL,UNUSED_ENV,SECRET_FRUIT",
"FRUIT=bananas",
@@ -276,7 +266,6 @@ def test_secure_path(container: TrackedContainer, tmp_path: pathlib.Path) -> Non
logs = container.run_and_wait(
timeout=5,
tty=True,
user="root",
volumes={p: {"bind": "/usr/bin/python", "mode": "ro"}},
command=["python", "--version"],
@@ -290,7 +279,6 @@ def test_startsh_multiple_exec(container: TrackedContainer) -> None:
logs = container.run_and_wait(
timeout=10,
no_warnings=False,
tty=True,
user="root",
environment=["GRANT_SUDO=yes"],
command=["start.sh", "sudo", "id"],
@@ -308,7 +296,6 @@ def test_rootless_triplet_change(container: TrackedContainer) -> None:
"""Container should change the username (`NB_USER`), the UID and the GID of the default user."""
logs = container.run_and_wait(
timeout=10,
tty=True,
user="root",
environment=["NB_USER=root", "NB_UID=0", "NB_GID=0"],
command=["id"],
@@ -322,7 +309,6 @@ def test_rootless_triplet_home(container: TrackedContainer) -> None:
"""Container should change the home directory for triplet NB_USER=root, NB_UID=0, NB_GID=0."""
logs = container.run_and_wait(
timeout=10,
tty=True,
user="root",
environment=["NB_USER=root", "NB_UID=0", "NB_GID=0"],
command=["bash", "-c", "echo HOME=${HOME} && getent passwd root"],
@@ -335,7 +321,6 @@ def test_rootless_triplet_sudo(container: TrackedContainer) -> None:
"""Container should not be started with sudo for triplet NB_USER=root, NB_UID=0, NB_GID=0."""
logs = container.run_and_wait(
timeout=10,
tty=True,
user="root",
environment=["NB_USER=root", "NB_UID=0", "NB_GID=0"],
command=["env"],

View File

@@ -27,7 +27,6 @@ def test_nbconvert(
logs = container.run_and_wait(
timeout=30,
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
tty=True,
command=["bash", "-c", command],
)
expected_file = f"{output_dir}/{test_file}.{output_format}"

View File

@@ -12,7 +12,6 @@ def test_spark_shell(container: TrackedContainer) -> None:
logs = container.run_and_wait(
timeout=60,
no_warnings=False,
tty=True,
command=["bash", "-c", 'spark-shell <<< "1+1"'],
)
warnings = TrackedContainer.get_warnings(logs)

View File

@@ -14,7 +14,6 @@ def test_cython(container: TrackedContainer) -> None:
logs = container.run_and_wait(
timeout=10,
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
tty=True,
command=[
"bash",
"-c",

View File

@@ -29,6 +29,5 @@ def test_check_extension(container: TrackedContainer, extension: str) -> None:
LOGGER.info(f"Checking the extension: {extension} ...")
container.run_and_wait(
timeout=10,
tty=True,
command=["jupyter", "labextension", "check", extension],
)

View File

@@ -40,7 +40,6 @@ def test_matplotlib(
LOGGER.info(description)
container.run_detached(
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
tty=True,
command=["bash", "-c", "sleep infinity"],
)

View File

@@ -12,11 +12,7 @@ def check_r_mimetypes(container: TrackedContainer) -> None:
LOGGER.info("Test that R command can be executed ...")
R_MIMETYPES_CHECK_CMD = 'if (length(getOption("jupyter.plot_mimetypes")) != 5) {stop("missing jupyter.plot_mimetypes")}'
command = ["Rscript", "-e", R_MIMETYPES_CHECK_CMD]
logs = container.run_and_wait(
timeout=10,
tty=True,
command=command,
)
logs = container.run_and_wait(timeout=10, command=command)
LOGGER.debug(f"{logs=}")
# If there is any output after this it means there was an error
assert logs.splitlines()[-1] == "Executing the command: " + " ".join(

View File

@@ -43,10 +43,7 @@ class CondaPackageHelper:
self.container = container
LOGGER.info(f"Starting container {self.container.image_name} ...")
self.container.run_detached(
tty=True,
command=["bash", "-c", "sleep infinity"],
)
self.container.run_detached(command=["bash", "-c", "sleep infinity"])
self.requested: dict[str, set[str]] | None = None
self.installed: dict[str, set[str]] | None = None

View File

@@ -12,11 +12,8 @@ def run_command(
command: str,
timeout: int = 5,
) -> str:
"""Runs the given package manager with its version argument."""
LOGGER.info(f"Test that the command '{command}' is working properly ...")
return container.run_and_wait(
timeout=timeout,
tty=True,
command=["bash", "-c", command],
)