source: trunk/tests.nix

Last change on this file was 211343e, checked in by Itamar Turner-Trauring <itamar@…>, at 2022-03-18T15:51:39Z

Set the Hypothesis profile in more robust way.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1let
2  sources = import nix/sources.nix;
3in
4# See default.nix for documentation about parameters.
5{ pkgsVersion ? "nixpkgs-21.11"
6, pkgs ? import sources.${pkgsVersion} { }
7, pypiData ? sources.pypi-deps-db
8, pythonVersion ? "python37"
9, mach-nix ? import sources.mach-nix {
10    inherit pkgs pypiData;
11    python = pythonVersion;
12  }
13}@args:
14let
15  # We would like to know the test requirements but mach-nix does not directly
16  # expose this information to us.  However, it is perfectly capable of
17  # determining it if we ask right...  This is probably not meant to be a
18  # public mach-nix API but we pinned mach-nix so we can deal with mach-nix
19  # upgrade breakage in our own time.
20  mach-lib = import "${sources.mach-nix}/mach_nix/nix/lib.nix" {
21    inherit pkgs;
22    lib = pkgs.lib;
23  };
24  tests_require = (mach-lib.extract "python37" ./. "extras_require" ).extras_require.test;
25
26  # Get the Tahoe-LAFS package itself.  This does not include test
27  # requirements and we don't ask for test requirements so that we can just
28  # re-use the normal package if it is already built.
29  tahoe-lafs = import ./. args;
30
31  # If we want to get tahoe-lafs into a Python environment with a bunch of
32  # *other* Python modules and let them interact in the usual way then we have
33  # to ask mach-nix for tahoe-lafs and those other Python modules in the same
34  # way - i.e., using `requirements`.  The other tempting mechanism,
35  # `packagesExtra`, inserts an extra layer of Python environment and prevents
36  # normal interaction between Python modules (as well as usually producing
37  # file collisions in the packages that are both runtime and test
38  # dependencies).  To get the tahoe-lafs we just built into the environment,
39  # put it into nixpkgs using an overlay and tell mach-nix to get tahoe-lafs
40  # from nixpkgs.
41  overridesPre = [(self: super: { inherit tahoe-lafs; })];
42  providers = tahoe-lafs.meta.mach-nix.providers // { tahoe-lafs = "nixpkgs"; };
43
44  # Make the Python environment in which we can run the tests.
45  python-env = mach-nix.mkPython {
46    # Get the packaging fixes we already know we need from putting together
47    # the runtime package.
48    inherit (tahoe-lafs.meta.mach-nix) _;
49    # Share the runtime package's provider configuration - combined with our
50    # own that causes the right tahoe-lafs to be picked up.
51    inherit providers overridesPre;
52    requirements = ''
53      # Here we pull in the Tahoe-LAFS package itself.
54      tahoe-lafs
55
56      # Unfortunately mach-nix misses all of the Python dependencies of the
57      # tahoe-lafs satisfied from nixpkgs.  Drag them in here.  This gives a
58      # bit of a pyrrhic flavor to the whole endeavor but maybe mach-nix will
59      # fix this soon.
60      #
61      # https://github.com/DavHau/mach-nix/issues/123
62      # https://github.com/DavHau/mach-nix/pull/386
63      ${tahoe-lafs.requirements}
64
65      # And then all of the test-only dependencies.
66      ${builtins.concatStringsSep "\n" tests_require}
67
68      # txi2p-tahoe is another dependency with an environment marker that
69      # mach-nix doesn't automatically pick up.
70      txi2p-tahoe
71    '';
72  };
73in
74# Make a derivation that runs the unit test suite.
75pkgs.runCommand "tahoe-lafs-tests" { } ''
76  export TAHOE_LAFS_HYPOTHESIS_PROFILE=ci
77  ${python-env}/bin/python -m twisted.trial -j $NIX_BUILD_CORES allmydata
78
79  # It's not cool to put the whole _trial_temp into $out because it has weird
80  # files in it we don't want in the store.  Plus, even all of the less weird
81  # files are mostly just trash that's not meaningful if the test suite passes
82  # (which is the only way we get $out anyway).
83  #
84  # The build log itself is typically available from `nix-store --read-log` so
85  # we don't need to record that either.
86  echo "passed" >$out
87
88''
Note: See TracBrowser for help on using the repository browser.