Skip to content

Commit 2b7191c

Browse files
authored
Merge pull request #1114 from maxhully/max/port-search-count-int
Parse port_search_count as an int
2 parents 82e971f + 8a6f537 commit 2b7191c

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

newsfragments/1115.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix an issue where number of search counts has been hard-default set to 5 by command-line default and ini setting could not override it.

pytest_postgresql/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def get_postgresql_option(option: str) -> Any:
3838
exec=get_postgresql_option("exec"),
3939
host=get_postgresql_option("host"),
4040
port=get_postgresql_option("port"),
41-
port_search_count=get_postgresql_option("port_search_count"),
41+
# Parse as int, because if it's defined in an INI file then it'll always be a string
42+
port_search_count=int(get_postgresql_option("port_search_count")),
4243
user=get_postgresql_option("user"),
4344
password=get_postgresql_option("password"),
4445
options=get_postgresql_option("options"),

pytest_postgresql/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with pytest-postgresql. If not, see <http://www.gnu.org/licenses/>.
1818
"""Plugin module of pytest-postgresql."""
19+
1920
from tempfile import gettempdir
2021

2122
from _pytest.config.argparsing import Parser
@@ -92,7 +93,6 @@ def pytest_addoption(parser: Parser) -> None:
9293
action="store",
9394
dest="postgresql_port_search_count",
9495
help=_help_port_search_count,
95-
default=5,
9696
)
9797

9898
parser.addoption("--postgresql-user", action="store", dest="postgresql_user", help=_help_user)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Asserts that port_search_count is 10.
2+
3+
That shows that it is not the default (5), and that we parsed it as an integer.
4+
"""
5+
6+
from pytest import FixtureRequest
7+
8+
from pytest_postgresql.config import get_config
9+
10+
11+
def test_assert_port_search_count_is_ten(request: FixtureRequest) -> None:
12+
"""Asserts that port_search_count is 10."""
13+
config = get_config(request)
14+
assert config["port_search_count"] == 10

tests/test_postgres_options_plugin.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ def test_postgres_loader_in_ini(pointed_pytester: Pytester) -> None:
5757
ret.assert_outcomes(passed=1)
5858

5959

60+
def test_postgres_port_search_count_in_cli_is_int(pointed_pytester: Pytester) -> None:
61+
"""Check that the --postgresql-port-search-count command line argument is parsed as an int."""
62+
pointed_pytester.copy_example("test_assert_port_search_count_is_ten.py")
63+
ret = pointed_pytester.runpytest(
64+
"--postgresql-port-search-count", "10", "test_assert_port_search_count_is_ten.py"
65+
)
66+
ret.assert_outcomes(passed=1)
67+
68+
69+
def test_postgres_port_search_count_in_ini_is_int(pointed_pytester: Pytester) -> None:
70+
"""Check that pytest.ini arguments are honored for load."""
71+
pointed_pytester.copy_example("test_assert_port_search_count_is_ten.py")
72+
pointed_pytester.makefile(".ini", pytest="[pytest]\npostgresql_port_search_count = 10\n")
73+
ret = pointed_pytester.runpytest("test_assert_port_search_count_is_ten.py")
74+
ret.assert_outcomes(passed=1)
75+
76+
6077
postgresql_proc_to_override = postgresql_proc()
6178

6279

0 commit comments

Comments
 (0)