Ament Build -test failed

The binary instructions are only sufficient to install the Debian packages and “use” what is coming with it.

If you want to build and test your own packages you need to follow the Linux-Development-Setup.

You likely already had pytest installed from a Debian package but unfortunately the latest Debian package version is still not new enough.

You are not supposed to run pytest on the workspace /ros2_ws. You should use ament test for this instead. The build tool makes sure to invoke the test on each package separately with various command line options as well as an environment which includes all dependencies of a specific package.