forked from dbfixtures/pytest-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
145 lines (112 loc) · 4.97 KB
/
plugin.py
File metadata and controls
145 lines (112 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright (C) 2016 by Clearcode <http://clearcode.cc>
# and associates (see AUTHORS).
# This file is part of pytest-postgresql.
# pytest-postgresql is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# pytest-postgresql is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with pytest-postgresql. If not, see <http://www.gnu.org/licenses/>.
"""Plugin module of pytest-postgresql."""
from tempfile import gettempdir
from _pytest.config.argparsing import Parser
from pytest_postgresql import factories
_help_executable = "Path to PostgreSQL executable"
_help_host = "Host at which PostgreSQL will accept connections"
_help_port = "Port at which PostgreSQL will accept connections"
_help_port_search_count = "Number of times, pytest-postgresql will search for free port"
_help_user = "PostgreSQL username"
_help_password = "PostgreSQL password"
_help_options = "PostgreSQL connection options"
_help_startparams = "Starting parameters for the PostgreSQL"
_help_unixsocketdir = "Location of the socket directory"
_help_dbname = "Default database name"
_help_load = "Dotted-style or entrypoint-style path to callable or path to SQL File"
_help_postgres_options = "Postgres executable extra parameters. Passed via the -o option to pg_ctl"
_help_drop_test_database = (
"Drop test database in noproc and client fixture, for the cases, "
"when database was not cleared due to errors in previous test runs. "
"Use cautiously and not on CI."
)
def pytest_addoption(parser: Parser) -> None:
"""Configure options for pytest-postgresql."""
parser.addini(
name="postgresql_exec", help=_help_executable, default="/usr/lib/postgresql/13/bin/pg_ctl"
)
parser.addini(name="postgresql_host", help=_help_host, default="127.0.0.1")
parser.addini(
name="postgresql_port",
help=_help_port,
default=None,
)
parser.addini(name="postgresql_port_search_count", help=_help_port_search_count, default=5)
parser.addini(name="postgresql_user", help=_help_user, default="postgres")
parser.addini(name="postgresql_password", help=_help_password, default=None)
parser.addini(name="postgresql_options", help=_help_options, default="")
parser.addini(name="postgresql_startparams", help=_help_startparams, default="-w")
parser.addini(name="postgresql_unixsocketdir", help=_help_unixsocketdir, default=gettempdir())
parser.addini(name="postgresql_dbname", help=_help_dbname, default="tests")
parser.addini(name="postgresql_load", type="pathlist", help=_help_load)
parser.addini(name="postgresql_postgres_options", help=_help_postgres_options, default="")
parser.addoption(
"--postgresql-exec",
action="store",
metavar="path",
dest="postgresql_exec",
help=_help_executable,
)
parser.addoption(
"--postgresql-host",
action="store",
dest="postgresql_host",
help=_help_host,
)
parser.addoption("--postgresql-port", action="store", dest="postgresql_port", help=_help_port)
parser.addoption(
"--postgresql-port-search-count",
action="store",
dest="postgresql_port_search_count",
help=_help_port_search_count,
)
parser.addoption("--postgresql-user", action="store", dest="postgresql_user", help=_help_user)
parser.addoption(
"--postgresql-password", action="store", dest="postgresql_password", help=_help_password
)
parser.addoption(
"--postgresql-options", action="store", dest="postgresql_options", help=_help_options
)
parser.addoption(
"--postgresql-startparams",
action="store",
dest="postgresql_startparams",
help=_help_startparams,
)
parser.addoption(
"--postgresql-unixsocketdir",
action="store",
dest="postgresql_unixsocketdir",
help=_help_unixsocketdir,
)
parser.addoption(
"--postgresql-dbname", action="store", dest="postgresql_dbname", help=_help_dbname
)
parser.addoption("--postgresql-load", action="append", dest="postgresql_load", help=_help_load)
parser.addoption(
"--postgresql-postgres-options",
action="store",
dest="postgresql_postgres_options",
help=_help_postgres_options,
)
parser.addoption(
"--postgresql-drop-test-database",
action="store_true",
dest="postgresql_drop_test_database",
help=_help_drop_test_database,
)
postgresql_proc = factories.postgresql_proc()
postgresql_noproc = factories.postgresql_noproc()
postgresql = factories.postgresql("postgresql_proc")