Forward lookup of the "run_tests" attribute (#34531)

fixes #34518

Fix an issue due to the MRO chain of the package wrapper
during build. Before this PR we were always returning
False when the builder object was created before the
run_tests method was monkey patched.
This commit is contained in:
Massimiliano Culpo 2022-12-15 09:35:33 +01:00 committed by GitHub
parent d2aa8466eb
commit 7056a4bffd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View file

@ -124,7 +124,12 @@ def __init__(self, wrapped_pkg_object, root_builder):
wrapper_cls = type(self)
bases = (package_cls, wrapper_cls)
new_cls_name = package_cls.__name__ + "Wrapper"
new_cls = type(new_cls_name, bases, {})
# Forward attributes that might be monkey patched later
new_cls = type(
new_cls_name,
bases,
{"run_tests": property(lambda x: x.wrapped_package_object.run_tests)},
)
new_cls.__module__ = package_cls.__module__
self.__class__ = new_cls
self.__dict__.update(wrapped_pkg_object.__dict__)

View file

@ -140,3 +140,17 @@ def test_build_time_tests_are_executed_from_default_builder():
assert os.environ.get("CHECK_CALLED") == "1", "Build time tests not executed"
assert os.environ.get("INSTALLCHECK_CALLED") == "1", "Install time tests not executed"
@pytest.mark.regression("34518")
@pytest.mark.usefixtures("builder_test_repository", "config", "working_env")
def test_monkey_patching_wrapped_pkg():
s = spack.spec.Spec("old-style-autotools").concretized()
builder = spack.builder.create(s.package)
assert s.package.run_tests is False
assert builder.pkg.run_tests is False
assert builder.pkg_with_dispatcher.run_tests is False
s.package.run_tests = True
assert builder.pkg.run_tests is True
assert builder.pkg_with_dispatcher.run_tests is True