@@ -0,0 +1,37 @@
1+{ lib, buildPythonPackage, fetchFromGitHub, postgresql, testing-common-database
2+, pg8000, pytestCheckHook, psycopg2, sqlalchemy }:
3+
4+buildPythonPackage rec {
5+ pname = "testing.postgresql";
6+ # Version 1.3.0 isn't working so let's use the latest commit from GitHub
7+ version = "unstable-2017-10-31";
8+
9+ src = fetchFromGitHub {
10+ owner = "tk0miya";
11+ repo = pname;
12+ rev = "c81ded434d00ec8424de0f9e1f4063c778c6aaa8";
13+ sha256 = "1asqsi38di768i1sc1qm1k068dj0906ds6lnx7xcbxws0s25m2q3";
14+ };
15+
16+ # Add PostgreSQL to search path
17+ prePatch = ''
18+ substituteInPlace src/testing/postgresql.py \
19+ --replace "/usr/local/pgsql" "${postgresql}"
20+ '';
21+
22+ propagatedBuildInputs = [ testing-common-database pg8000 ];
23+
24+ # Fix tests for Darwin build. See:
25+ # https://github.com/NixOS/nixpkgs/pull/74716#issuecomment-598546916
26+ __darwinAllowLocalNetworking = true;
27+
28+ checkInputs = [ pytestCheckHook psycopg2 sqlalchemy ];
29+
30+ meta = with lib; {
31+ description = "Use temporary postgresql instance in testing";
32+ homepage = "https://github.com/tk0miya/testing.postgresql";
33+ license = licenses.asl20;
34+ platforms = platforms.linux;
35+ maintainers = with maintainers; [ jluttine ];
36+ };
37+}