Python Testing with pytest: Chapter 2 testing a package

Reading this chapter several times I’m trying to understand how to properly run test against the code of a package.

It looks to me that we need to install the package with pip before running tests against it. I know we can use the -e flag in pip to make the package editable while developing. But, why not testing directly the code in the src folder instead of the one installed? What about testing code that is internal to the package and not exposed outside the package?(do not know if that is correct in python)

I’m just trying to understand the correct way to test in python.

Thanks

These are great questions.

You are correct that -e is useful for testing code you are working on. That’s included in chapter 13, “Debugging Test Failures”, under section “Installing Cards in Editable Mode”.

Regarding testing code that is internal to a package and not exposed outside the package, see chapter 12, “Testing Scripts and Applications”, under section “Separating Code into src and tests Directories”.

However, short answer is use pythonpath setting. See API Reference — pytest documentation