The following Nix shell declaration has a common bug:

let
  pkgs = import ../nixpkgs.nix;
in
pkgs.mkShell {
  packages = [
    pkgs.bashInteractive
    pkgs.python3Packages.pytest
    pkgs.python310
  ];
}

Running python within the shell works, and running pytest works, but the two are not connected:

$ python -c "import pytest"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pytest'

The fix is to explicitly include the Python packages with Python itself:

let
  pkgs = import ../nixpkgs.nix;
in
pkgs.mkShell {
  packages = [
    pkgs.bashInteractive
    (pkgs.python310.withPackages (pythonPackages: [ pythonPackages.pytest ]))
  ];
}

Many interpreters support this pattern. Have a look for “withPackages” in the nixpkgs manual.