
josealobato
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
Marked As Solved

brianokken
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
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /slackware
- /julia
- /c
- /neovim