Backport #186 from py-py to fix macOS failures (#26653)
Backport #186 from py-py to fix macOS failures (#26653)

Backports the relevant bits of https://github.com/pytest-dev/py/commit/0f77b6e66f79c07dbb657e2b4a7e94263eacc01b
LLNL/spack,LLNL/spack,LLNL/spack,LLNL/spack,LLNL/spack