GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — install_test.py: append to install-time test log for multiple test phases (#50477) by AlexanderRichert-NOAA · Pull Request #569 · JCSDA/spack

install_test.py: append to install-time test log for multiple test phases (#50477) #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
climbfuji merged 1 commit into JCSDA:feature/update_to_spack_v1 from AlexanderRichert-NOAA:test_log_fix_oct25
Oct 24, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

install_test.py: append to install-time test log for multiple test phases (#50477) #569

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
291de99
install_test.py: append to install-time test log for multiple test ph…
AlexanderRichert-NOAA Oct 17, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
install_test.py: append to install-time test log for multiple test ph…
…ases (spack#50477)

* Append to install-time test log for multiple test phases

Signed-off-by: Alex Richert <[email protected]>

* log.py: fix tmp dir arg

Signed-off-by: Alex Richert <[email protected]>

* log.py: fix typo (:)

Signed-off-by: Alex Richert <[email protected]>

* use existing tests/pkg

Signed-off-by: Alex Richert <[email protected]>

* remove new test file/pkg

Signed-off-by: Alex Richert <[email protected]>

* test/cmd/install.py: skip log append check for win32

Signed-off-by: Alex Richert <[email protected]>

* test/cmd/install.py: skip install 'tests' for win32

Signed-off-by: Alex Richert <[email protected]>

* test/cmd/install.py: fix install test-skip logic (win32)

Signed-off-by: Alex Richert <[email protected]>

* test/cmd/install.py: skip test_package_output for windows

Signed-off-by: Alex Richert <[email protected]>

* Revert "test/cmd/install.py: skip test_package_output for windows"

This reverts commit f14beed.

Signed-off-by: Alex Richert <[email protected]>

---------

Signed-off-by: Alex Richert <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@AlexanderRichert-NOAA
AlexanderRichert-NOAA committed Oct 23, 2025
commit 291de994f651cbed56272b38491af7b5d828de51

There are no files selected for viewing

4 changes: 3 additions & 1 deletion 4 lib/spack/spack/install_test.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ def test_logger(self, verbose: bool = False, externals: bool = False):
fs.touch(self.test_log_file) # Otherwise log_parse complains
fs.set_install_permissions(self.test_log_file)

with spack.llnl.util.tty.log.log_output(self.test_log_file, verbose) as self._logger:
with spack.llnl.util.tty.log.log_output(
self.test_log_file, verbose, append=True
) as self._logger:
with self.logger.force_echo(): # type: ignore[union-attr]
tty.msg("Testing package " + colorize(r"@*g{" + self.pkg_id + r"}"))

Expand Down
27 changes: 21 additions & 6 deletions 27 lib/spack/spack/llnl/util/tty/log.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,14 @@ class FileWrapper:
object.
"""

def __init__(self, file_like):
def __init__(self, file_like, append=False):
# This records whether the file-like object returned by "unwrap" is
# purely in-memory. In that case a subprocess will need to explicitly
# transmit the contents to the parent.
self.write_in_parent = False

self.file_like = file_like
self.append = append

if isinstance(file_like, str):
self.open = True
Expand All @@ -358,7 +359,8 @@ def __init__(self, file_like):
def unwrap(self):
if self.open:
if self.file_like:
self.file = open(self.file_like, "w", encoding="utf-8")
mode = "a" if self.append else "w"
self.file = open(self.file_like, mode, encoding="utf-8")
else:
self.file = io.StringIO()
return self.file
Expand Down Expand Up @@ -424,7 +426,14 @@ class nixlog:
"""

def __init__(
self, file_like=None, echo=False, debug=0, buffer=False, env=None, filter_fn=None
self,
file_like=None,
echo=False,
debug=0,
buffer=False,
env=None,
filter_fn=None,
append=False,
):
"""Create a new output log context manager.

Expand All @@ -437,6 +446,7 @@ def __init__(
this doesn't set up any *new* buffering
filter_fn (callable, optional): Callable[str] -> str to filter each
line of output
append (bool): whether to append to file ('a' mode)

log_output can take either a file object or a filename. If a
filename is passed, the file will be opened and closed entirely
Expand All @@ -456,6 +466,7 @@ def __init__(
self.debug = debug
self.buffer = buffer
self.filter_fn = filter_fn
self.append = append

self._active = False # used to prevent re-entry

Expand Down Expand Up @@ -496,7 +507,7 @@ def __enter__(self):
raise RuntimeError("file argument must be set by either __init__ or __call__")

# set up a stream for the daemon to write to
self.log_file = FileWrapper(self.file_like)
self.log_file = FileWrapper(self.file_like, append=self.append)

# record parent color settings before redirecting. We do this
# because color output depends on whether the *original* stdout
Expand Down Expand Up @@ -735,7 +746,9 @@ class winlog:
Does not support the use of 'v' toggling as nixlog does.
"""

def __init__(self, file_like=None, echo=False, debug=0, buffer=False, filter_fn=None):
def __init__(
self, file_like=None, echo=False, debug=0, buffer=False, filter_fn=None, append=False
):
self.debug = debug
self.echo = echo
self.logfile = file_like
Expand All @@ -745,6 +758,7 @@ def __init__(self, file_like=None, echo=False, debug=0, buffer=False, filter_fn=
self._ioflag = False
self.old_stdout = sys.stdout
self.old_stderr = sys.stderr
self.append = append

def __enter__(self):
if self._active:
Expand All @@ -760,7 +774,8 @@ def __enter__(self):
sys.stdout = self.logfile
sys.stderr = self.logfile
else:
self.writer = open(self.logfile, mode="wb+")
write_mode = "ab+" if self.append else "wb+"
self.writer = open(self.logfile, mode=write_mode)
self.reader = open(self.logfile, mode="rb+")

# Dup stdout so we can still write to it after redirection
Expand Down
13 changes: 12 additions & 1 deletion 13 lib/spack/spack/test/cmd/install.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_package_output(capsys, install_mockery, mock_fetch):
# when nested AND in pytest
spec = spack.concretize.concretize_one("printing-package")
pkg = spec.package
PackageInstaller([pkg], explicit=True, verbose=True).install()
PackageInstaller([pkg], explicit=True, verbose=True, tests=sys.platform != "win32").install()

with gzip.open(pkg.install_log_path, "rt") as f:
out = f.read()
Expand All @@ -151,6 +151,17 @@ def test_package_output(capsys, install_mockery, mock_fetch):
assert "BEFORE INSTALL" in out
assert "AFTER INSTALL" in out

if not sys.platform == "win32":
# Check that install-time test log contains check and installcheck output
log_path = pkg.tester.archived_install_test_log
assert os.path.exists(log_path), f"Missing install-time test log at {log_path}"

with open(log_path, "r", encoding="utf-8") as f:
test_log_contents = f.read()

assert "PRINTING PACKAGE CHECK" in test_log_contents
assert "PRINTING PACKAGE INSTALLCHECK" in test_log_contents


@pytest.mark.disable_clean_stage_check
def test_install_output_on_build_error(
Expand Down
17 changes: 17 additions & 0 deletions 17 lib/spack/spack/test/llnl/util/tty/log.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ def test_log_output_with_filter(capfd, tmp_path: pathlib.Path):
assert capfd.readouterr()[0] == "bar blah\nblah bar\nbar bar\n"


def test_log_output_with_filter_and_append(capfd, tmp_path: pathlib.Path):
with working_dir(str(tmp_path)):
with log.log_output("foo.txt", filter_fn=_log_filter_fn):
print("foo blah")
print("blah foo")
print("foo foo")

with open("foo.txt", encoding="utf-8") as f:
assert f.read() == "foo blah\nblah foo\nfoo foo\n"

with log.log_output("foo.txt", filter_fn=_log_filter_fn, append=True):
print("more foo more blah")

with open("foo.txt", encoding="utf-8") as f:
assert f.read() == "foo blah\nblah foo\nfoo foo\nmore foo more blah\n"


@pytest.mark.skipif(not which("echo"), reason="needs echo command")
def test_log_subproc_and_echo_output_no_capfd(capfd, tmp_path: pathlib.Path):
echo = which("echo", required=True)
Expand Down
12 changes: 10 additions & 2 deletions 12 var/spack/test_repos/spack_repo/builtin_mock/packages/printing_package/package.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import os

from spack_repo.builtin_mock.build_systems.generic import Package
from spack_repo.builtin_mock.build_systems.makefile import MakefilePackage

from spack.package import *


class PrintingPackage(Package):
class PrintingPackage(MakefilePackage):
"""This package prints some output from its install method.

We use this to test whether that output is properly logged.
Expand All @@ -28,6 +28,14 @@ def install(self, spec, prefix):

print("AFTER INSTALL")

def check(self):
"""Run build-time tests."""
print("PRINTING PACKAGE CHECK")

def installcheck(self):
"""Run install-time tests."""
print("PRINTING PACKAGE INSTALLCHECK")

def test_print(self):
"""Test print example."""

Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402809 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.