summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2022-12-15 09:35:33 +0100
committerGitHub <noreply@github.com>2022-12-15 09:35:33 +0100
commit7056a4bffd8f37615bc5efee8f02a400dceaec5c (patch)
tree452ce5d618eed1455e212ea337e409524e29691b /lib
parentd2aa8466eb38f3b7c9bf17692ba5e8ddf8571c4a (diff)
downloadspack-7056a4bffd8f37615bc5efee8f02a400dceaec5c.tar.gz
spack-7056a4bffd8f37615bc5efee8f02a400dceaec5c.tar.bz2
spack-7056a4bffd8f37615bc5efee8f02a400dceaec5c.tar.xz
spack-7056a4bffd8f37615bc5efee8f02a400dceaec5c.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/builder.py7
-rw-r--r--lib/spack/spack/test/builder.py14
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/spack/spack/builder.py b/lib/spack/spack/builder.py
index 520d983d41..ae4f4f2fc2 100644
--- a/lib/spack/spack/builder.py
+++ b/lib/spack/spack/builder.py
@@ -124,7 +124,12 @@ def _create(pkg):
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__)
diff --git a/lib/spack/spack/test/builder.py b/lib/spack/spack/test/builder.py
index 944514b610..a3af33b773 100644
--- a/lib/spack/spack/test/builder.py
+++ b/lib/spack/spack/test/builder.py
@@ -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