Howto disable tests in buildPythonApplication

I’m trying to package a development version of ansible-playbook-grapher in order to try out a fix that the author is developing. My code looks like this:

  ansible-playbook-grapher_repo_v1_1_2-dev = pkgs.fetchFromGitHub {
    owner = "haidaraM";
    repo = "ansible-playbook-grapher";
    rev = "1d804bbb01eab5c07d42f6eb4917e1d643e3c4b3";
    sha256 = "spAI/eF+U5VMTj7ac7s01xZ5wEfyHAQ6jFyCvcEU6mE=";
  ansible-playbook-grapher = pkgs.python3Packages.buildPythonApplication {
    pname = "ansible-playbook-grapher";
    version = "1.1.2-dev";
    buildInputs = [ pkgs.graphviz ];
    propagatedBuildInputs = with pkgs.python3Packages; [ ansible-core colour lxml ];
    src = ansible-playbook-grapher_repo_v1_1_2-dev;

When trying to build this, I get

setting SOURCE_DATE_EPOCH to timestamp 315619200 of file source/tests/
patching sources
no configure script, doing nothing
Executing setuptoolsBuildPhase
Unhandled error:
 Traceback (most recent call last):
  File "/nix/store/5hckvvf3cxif51vpph7fsqjsjznab0yb-python3.9-ansible-core-2.13.0/lib/python3.9/site-packages/ansible/utils/", line 85, in makedirs_safe
    os.makedirs(b_rpath, mode)
  File "/nix/store/gwlgfywzqypv91rxw916v81mpzhckdz5-python3-3.9.13/lib/python3.9/", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/nix/store/gwlgfywzqypv91rxw916v81mpzhckdz5-python3-3.9.13/lib/python3.9/", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/nix/store/gwlgfywzqypv91rxw916v81mpzhckdz5-python3-3.9.13/lib/python3.9/", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: b'/homeless-shelter'

It seems that this happens when the tests are executed. What would be the cleanest way to simply not run the tests when building the derivation? Related question: Is it generally considered desirable to run the unittests in the derivation build process, or is it considered ok to trust the derivation authors that they have verified that things work?

Btw this seems to be caused by this Ansible issue: ansible CLI tools error out if `$HOME` isn't writable · Issue #75019 · ansible/ansible · GitHub

Set doCheck to false: NixOS - Nixpkgs 22.05 manual

It’s true by default for python, because the testing interface is well defined (unlike for, say, C).

Of course it is! It’s like arguing that we can’t package anything because we expect authors to have written holey, insecure code. Of course they do write holey, insecure code all the time, but that doesn’t mean such isn’t packaged constantly :wink:

I’d even go a step further and do my best to ensure the testing works, treating disabling the check phase as a last resort. It helps notify me when a nixos-specific issue crops up, or something changes that makes my packaging invalid. Or if upstream releases a broken release.

If you modify the test suite in a way that feels like it would be generally useful, it’s good practice to then also send a PR upstream, and in the long term remove your downstream hack :slight_smile:

In this case, you could attempt to change $HOME to something in $TMP. Not sure off the top of my head if that’s the idiomatic way of doing this with nixpkgs, but I’m sure there’s an example of this exact use case somewhere.

You could also change the test case to use the flags that change the cache directory. I think that’s a better solution, especially if you upstream that, it’d keep all other projects trying to test this without a home directory from having to repeat your sleuthing. You’d apply changes in the patchPhase, ideally in the form of a patch file created from a git commit to make upstreaming this easy.

While I haven’t read the tests, I think that might even make them more robust; it sounds like, currently, they may fail/pass purely because of existing things in the ansible cache of the person executing them :wink:

1 Like

Thanks for the detailed reply! The doCheck didn’t do the trick for me - maybe my interpretation that the error occurred during the tests wasn’t correct after all. I’ll give an update once I find the time to look a bit more into this. And if I do, I’ll check if this is something that could be improved upstream :slight_smile:

It’s during the setuptoolsBuildPhase, which means it’s running python build.

PermissionError: [Errno 13] Permission denied: b'/homeless-shelter'

This is can be solved with prePatch = ''export HOME=$NIX_BUILD_TOP''; or something similar. In nix builds, HOME is set to /homeless-shelter, as builds shouldn’t really be making use of it.

I’m not sure what is calling ansible-core, but that’s what’s trying to create the path.

Hosted by Flying Circus.