pythonRemoveTestsDir hook being run before checkPhase

I’m working on packaging jax at the moment and according to the nix docs I should be using something like

  checkInputs = [ pytest ];
  checkPhase = "pytest tests/";

And this makes sense since the jax docs explain they use pytest as well.

But when I build the derivation, I get:

...
Installing collected packages: jax
Successfully installed jax-0.2.19
/private/tmp/nix-build-python3.9-jax-0.2.19.drv-0/jax-0.2.19
Finished executing pipInstallPhase
post-installation fixup
strip is /nix/store/a2ry0yj3mav03l2fl6pkr3a2qhficyw7-cctools-binutils-darwin-949.0.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/2s0kpkv2p8k601g38v466bhf0lnh71jz-python3.9-jax-0.2.19/lib 
patching script interpreter paths in /nix/store/2s0kpkv2p8k601g38v466bhf0lnh71jz-python3.9-jax-0.2.19
Executing pythonRemoveTestsDir
Finished executing pythonRemoveTestsDir
running install tests
============================= test session starts ==============================
platform darwin -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /private/tmp/nix-build-python3.9-jax-0.2.19.drv-0/jax-0.2.19
collected 0 items                                                              

============================ no tests ran in 0.01s =============================
ERROR: file or directory not found: tests/

What’s going on here? Shouldn’t the pythonRemoveTestsDir hook only be run after the checkPhase? How else do I run tests?

There’s actually no issue with the pythonRemoveTestsDir as it only removes $out/${python.sitePackages}/test.

pythonRemoveTestsDir() {
    echo "Executing pythonRemoveTestsDir"

    rm -rf $out/@pythonSitePackages@/tests
    rm -rf $out/@pythonSitePackages@/test

    echo "Finished executing pythonRemoveTestsDir"
}

The issue is that the sdist on pypi doesn’t include tests

$ ls -l jax-0.2.19
drwxr-x---    - jon 12 Aug 21:41 jax
drwxr-x---    - jon 12 Aug 21:41 jax.egg-info
.rw-r-----  597 jon 12 Aug 21:41 PKG-INFO
.rw-r-----  22k jon 12 Aug 21:41 README.md
.rw-r-----  363 jon 12 Aug 21:41 setup.cfg
.rw-r----- 2.5k jon 12 Aug 21:41 setup.py

you can see that’s quite a bit smaller than GitHub - google/jax: Composable transformations of Python+NumPy programs: differentiate, vectorize, JIT to GPU/TPU, and more.

In short, fetch the source code from github, and you will have tests.

1 Like

Ah, brilliant! I’ll give that a shot!