diff --git a/newsfragments/1115.bugfix.rst b/newsfragments/1115.bugfix.rst new file mode 100644 index 00000000..fecf52df --- /dev/null +++ b/newsfragments/1115.bugfix.rst @@ -0,0 +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. diff --git a/pytest_postgresql/config.py b/pytest_postgresql/config.py index a772136e..b7c2d87e 100644 --- a/pytest_postgresql/config.py +++ b/pytest_postgresql/config.py @@ -38,7 +38,8 @@ def get_postgresql_option(option: str) -> Any: exec=get_postgresql_option("exec"), host=get_postgresql_option("host"), port=get_postgresql_option("port"), - port_search_count=get_postgresql_option("port_search_count"), + # Parse as int, because if it's defined in an INI file then it'll always be a string + port_search_count=int(get_postgresql_option("port_search_count")), user=get_postgresql_option("user"), password=get_postgresql_option("password"), options=get_postgresql_option("options"), diff --git a/pytest_postgresql/plugin.py b/pytest_postgresql/plugin.py index 04a5c3ef..5c3f4096 100644 --- a/pytest_postgresql/plugin.py +++ b/pytest_postgresql/plugin.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with pytest-postgresql. If not, see . """Plugin module of pytest-postgresql.""" + from tempfile import gettempdir from _pytest.config.argparsing import Parser @@ -92,7 +93,6 @@ def pytest_addoption(parser: Parser) -> None: action="store", dest="postgresql_port_search_count", help=_help_port_search_count, - default=5, ) parser.addoption("--postgresql-user", action="store", dest="postgresql_user", help=_help_user) diff --git a/tests/examples/test_assert_port_search_count_is_ten.py b/tests/examples/test_assert_port_search_count_is_ten.py new file mode 100644 index 00000000..aa0e2eb1 --- /dev/null +++ b/tests/examples/test_assert_port_search_count_is_ten.py @@ -0,0 +1,14 @@ +"""Asserts that port_search_count is 10. + +That shows that it is not the default (5), and that we parsed it as an integer. +""" + +from pytest import FixtureRequest + +from pytest_postgresql.config import get_config + + +def test_assert_port_search_count_is_ten(request: FixtureRequest) -> None: + """Asserts that port_search_count is 10.""" + config = get_config(request) + assert config["port_search_count"] == 10 diff --git a/tests/test_postgres_options_plugin.py b/tests/test_postgres_options_plugin.py index c87fc3ea..4cb005f6 100644 --- a/tests/test_postgres_options_plugin.py +++ b/tests/test_postgres_options_plugin.py @@ -57,6 +57,23 @@ def test_postgres_loader_in_ini(pointed_pytester: Pytester) -> None: ret.assert_outcomes(passed=1) +def test_postgres_port_search_count_in_cli_is_int(pointed_pytester: Pytester) -> None: + """Check that the --postgresql-port-search-count command line argument is parsed as an int.""" + pointed_pytester.copy_example("test_assert_port_search_count_is_ten.py") + ret = pointed_pytester.runpytest( + "--postgresql-port-search-count", "10", "test_assert_port_search_count_is_ten.py" + ) + ret.assert_outcomes(passed=1) + + +def test_postgres_port_search_count_in_ini_is_int(pointed_pytester: Pytester) -> None: + """Check that pytest.ini arguments are honored for load.""" + pointed_pytester.copy_example("test_assert_port_search_count_is_ten.py") + pointed_pytester.makefile(".ini", pytest="[pytest]\npostgresql_port_search_count = 10\n") + ret = pointed_pytester.runpytest("test_assert_port_search_count_is_ten.py") + ret.assert_outcomes(passed=1) + + postgresql_proc_to_override = postgresql_proc()