Repository: spack/spack

Issue:
spack concretize --test root not working with `concretizer:unify:true`
### Steps to reproduce

When concretizing an environment with the `concretizer:unify:true` option, test dependencies are not included. For example, for `py-numpy`:

```console
$ spack env activate --temp
$ spack add py-numpy
$ spack concretize --test root

==> Concretized py-numpy
 -   wtzvq75  py-numpy@1.24.1%gcc@9.4.0+blas+lapack build_system=python_pip patches=873745d arch=linux-ubuntu20.04-haswell
 -   doyqmuv      ^openblas@0.3.21%gcc@9.4.0~bignuma~consistent_fpcsr+fortran~ilp64+locking+pic+shared build_system=makefile patches=a4c642f,c20f518,d3d9b15 symbol_suffix=none threads=none arch=linux-ubuntu20.04-haswell
 -   uqiudrk          ^perl@5.36.0%gcc@9.4.0+cpanm+open+shared+threads build_system=generic arch=linux-ubuntu20.04-haswell
 -   aslz6su              ^berkeley-db@18.1.40%gcc@9.4.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-ubuntu20.04-haswell
 -   ocfzlqh      ^py-cython@0.29.32%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   mxa3xpi      ^py-pip@22.2.2%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-haswell
 -   72sgwn6      ^py-setuptools@63.0.0%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-haswell
 -   h2znj2g      ^py-wheel@0.37.1%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-haswell
 -   caya4n5      ^python@3.10.8%gcc@9.4.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib build_system=generic patches=0d98e93,7d40923,f2fd060 arch=linux-ubuntu20.04-haswell
 -   ydyacsv          ^bzip2@1.0.8%gcc@9.4.0~debug~pic+shared build_system=generic arch=linux-ubuntu20.04-haswell
 -   w7ujymt              ^diffutils@3.8%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   jqaacda          ^expat@2.5.0%gcc@9.4.0+libbsd build_system=autotools arch=linux-ubuntu20.04-haswell
 -   mtapc5h              ^libbsd@0.11.7%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   ia2biir                  ^libmd@1.0.4%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   i56ki72          ^gdbm@1.23%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   ifp4wnk          ^gettext@0.21.1%gcc@9.4.0+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=linux-ubuntu20.04-haswell
 -   wjc7abg              ^libiconv@1.17%gcc@9.4.0 build_system=autotools libs=shared,static arch=linux-ubuntu20.04-haswell
 -   z4y5eea              ^libxml2@2.10.3%gcc@9.4.0~python build_system=autotools arch=linux-ubuntu20.04-haswell
 -   k5oo6xr              ^tar@1.34%gcc@9.4.0 build_system=autotools zip=pigz arch=linux-ubuntu20.04-haswell
 -   bh3ab5f                  ^pigz@2.7%gcc@9.4.0 build_system=makefile arch=linux-ubuntu20.04-haswell
 -   j4tfb7y                  ^zstd@1.5.2%gcc@9.4.0+programs build_system=makefile compression=none libs=shared,static arch=linux-ubuntu20.04-haswell
 -   7yp42wt          ^libffi@3.4.4%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   t2obdxt          ^libxcrypt@4.4.33%gcc@9.4.0~obsolete_api build_system=autotools arch=linux-ubuntu20.04-haswell
 -   tyhrbev          ^ncurses@6.4%gcc@9.4.0~symlinks+termlib abi=none build_system=autotools arch=linux-ubuntu20.04-haswell
 -   oybwdkj          ^openssl@1.1.1s%gcc@9.4.0~docs~shared build_system=generic certs=mozilla arch=linux-ubuntu20.04-haswell
 -   zzaqthe              ^ca-certificates-mozilla@2023-01-10%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-haswell
 -   wxogjmo          ^pkgconf@1.8.0%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   5ovlhw6          ^readline@8.2%gcc@9.4.0 build_system=autotools patches=bbf97f1 arch=linux-ubuntu20.04-haswell
 -   ajanzpd          ^sqlite@3.40.1%gcc@9.4.0+column_metadata+dynamic_extensions+fts~functions+rtree build_system=autotools arch=linux-ubuntu20.04-haswell
 -   qvelodw          ^util-linux-uuid@2.38.1%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   otaq3hx          ^xz@5.4.1%gcc@9.4.0~pic build_system=autotools libs=shared,static arch=linux-ubuntu20.04-haswell
 -   kbkuyym          ^zlib@1.2.13%gcc@9.4.0+optimize+pic+shared build_system=makefile arch=linux-ubuntu20.04-haswell
```

With `concretizer:unify` set to `when_possible`, the concretization is correct (test dependencies are included):

```console
$ spack config --scope env:/tmp/spack-mm7i_dhn add concretizer:unify:when_possible
$ spack concretize --test root
==> Concretized py-numpy
 -   wtzvq75  py-numpy@1.24.1%gcc@9.4.0+blas+lapack build_system=python_pip patches=873745d arch=linux-ubuntu20.04-haswell
 -   doyqmuv      ^openblas@0.3.21%gcc@9.4.0~bignuma~consistent_fpcsr+fortran~ilp64+locking+pic+shared build_system=makefile patches=a4c642f,c20f518,d3d9b15 symbol_suffix=none threads=none arch=linux-ubuntu20.04-haswell
 -   uqiudrk          ^perl@5.36.0%gcc@9.4.0+cpanm+open+shared+threads build_system=generic arch=linux-ubuntu20.04-haswell
 -   aslz6su              ^berkeley-db@18.1.40%gcc@9.4.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-ubuntu20.04-haswell
 -   ocfzlqh      ^py-cython@0.29.32%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   pfrm5f7      ^py-hypothesis@6.23.1%gcc@9.4.0~django~numpy~pandas build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   cofsslw          ^py-attrs@22.1.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   7rb74jr          ^py-sortedcontainers@2.1.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   mxa3xpi      ^py-pip@22.2.2%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-haswell
 -   h55f4wa      ^py-pytest@7.1.3%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   a46bxgn          ^py-iniconfig@1.1.1%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   35unjfe          ^py-packaging@21.3%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   7w5h5j2              ^py-pyparsing@3.0.9%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   lu664oh          ^py-pluggy@1.0.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   fjnnidt          ^py-py@1.11.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   sdaeebv          ^py-setuptools-scm@7.0.5%gcc@9.4.0+toml build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   c6k3lyk          ^py-tomli@2.0.1%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   72sgwn6      ^py-setuptools@63.0.0%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-haswell
 -   hdxzcik      ^py-typing-extensions@4.3.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   mcubj3m          ^py-flit-core@3.7.1%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-haswell
 -   h2znj2g      ^py-wheel@0.37.1%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-haswell
 -   caya4n5      ^python@3.10.8%gcc@9.4.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib build_system=generic patches=0d98e93,7d40923,f2fd060 arch=linux-ubuntu20.04-haswell
 -   ydyacsv          ^bzip2@1.0.8%gcc@9.4.0~debug~pic+shared build_system=generic arch=linux-ubuntu20.04-haswell
 -   w7ujymt              ^diffutils@3.8%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   jqaacda          ^expat@2.5.0%gcc@9.4.0+libbsd build_system=autotools arch=linux-ubuntu20.04-haswell
 -   mtapc5h              ^libbsd@0.11.7%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   ia2biir                  ^libmd@1.0.4%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   i56ki72          ^gdbm@1.23%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   ifp4wnk          ^gettext@0.21.1%gcc@9.4.0+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=linux-ubuntu20.04-haswell
 -   wjc7abg              ^libiconv@1.17%gcc@9.4.0 build_system=autotools libs=shared,static arch=linux-ubuntu20.04-haswell
 -   z4y5eea              ^libxml2@2.10.3%gcc@9.4.0~python build_system=autotools arch=linux-ubuntu20.04-haswell
 -   k5oo6xr              ^tar@1.34%gcc@9.4.0 build_system=autotools zip=pigz arch=linux-ubuntu20.04-haswell
 -   bh3ab5f                  ^pigz@2.7%gcc@9.4.0 build_system=makefile arch=linux-ubuntu20.04-haswell
 -   j4tfb7y                  ^zstd@1.5.2%gcc@9.4.0+programs build_system=makefile compression=none libs=shared,static arch=linux-ubuntu20.04-haswell
 -   7yp42wt          ^libffi@3.4.4%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   t2obdxt          ^libxcrypt@4.4.33%gcc@9.4.0~obsolete_api build_system=autotools arch=linux-ubuntu20.04-haswell
 -   tyhrbev          ^ncurses@6.4%gcc@9.4.0~symlinks+termlib abi=none build_system=autotools arch=linux-ubuntu20.04-haswell
 -   oybwdkj          ^openssl@1.1.1s%gcc@9.4.0~docs~shared build_system=generic certs=mozilla arch=linux-ubuntu20.04-haswell
 -   zzaqthe              ^ca-certificates-mozilla@2023-01-10%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-haswell
 -   wxogjmo          ^pkgconf@1.8.0%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   5ovlhw6          ^readline@8.2%gcc@9.4.0 build_system=autotools patches=bbf97f1 arch=linux-ubuntu20.04-haswell
 -   ajanzpd          ^sqlite@3.40.1%gcc@9.4.0+column_metadata+dynamic_extensions+fts~functions+rtree build_system=autotools arch=linux-ubuntu20.04-haswell
 -   qvelodw          ^util-linux-uuid@2.38.1%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-haswell
 -   otaq3hx          ^xz@5.4.1%gcc@9.4.0~pic build_system=autotools libs=shared,static arch=linux-ubuntu20.04-haswell
 -   kbkuyym          ^zlib@1.2.13%gcc@9.4.0+optimize+pic+shared build_system=makefile arch=linux-ubuntu20.04-haswell
```

This is probably related to why the workaround for  #29447 does not work with `concretizer:unify:true`

### Error message

_No response_

### Information on your system

* **Spack:** 0.20.0.dev0 (eac04af0e79dc5ceb0b89b81798b0bf4fa58a862)
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-haswell
* **Concretizer:** clingo

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:

Resolving patch:
diff --git a/lib/spack/spack/concretize.py b/lib/spack/spack/concretize.py
--- a/lib/spack/spack/concretize.py
+++ b/lib/spack/spack/concretize.py
@@ -743,9 +743,7 @@ def _concretize_specs_together_new(*abstract_specs, **kwargs):
     import spack.solver.asp
 
     solver = spack.solver.asp.Solver()
-    solver.tests = kwargs.get("tests", False)
-
-    result = solver.solve(abstract_specs)
+    result = solver.solve(abstract_specs, tests=kwargs.get("tests", False))
     result.raise_if_unsat()
     return [s.copy() for s in result.specs]
 


Test patch: