From 11c896fd0e1b7e54eb102a0cf476af709e38028a Mon Sep 17 00:00:00 2001 From: Jean-Frederic Clere Date: Thu, 22 Oct 2026 09:44:34 +0000 Subject: [PATCH] Allow the --httpd --conf parameter in unix too. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939326 13f79535-47bb-0310-9956-ffa450edef68 --- test/conftest.py | 8 ++--- test/modules/ssl/conftest.py | 2 +- test/pyhttpd/env.py | 58 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 1af75404ee..7c4057fbe1 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -36,7 +36,7 @@ def pytest_ignore_collect(collection_path, config): return True def pytest_report_header(config, start_path): - env = HttpdTestEnv() + env = HttpdTestEnv(pytestconfig=config) return f"[apache httpd: {env.get_httpd_version()}, mpm: {env.mpm_module}, {env.prefix}]" def pytest_addoption(parser): @@ -152,9 +152,9 @@ test_src_dir = {test_dir} def pytest_configure(config): - httpd_opt = config.getoption("--httpd", default=None) - if httpd_opt and sys.platform == "win32": - _generate_config_ini(config) + # --httpd/--conf overrides are now applied in memory by + # HttpdTestEnv._apply_cli_overrides(); config.ini is never rewritten. + pass def pytest_collection_modifyitems(config, items): diff --git a/test/modules/ssl/conftest.py b/test/modules/ssl/conftest.py index 46f8f3074b..175c740ee9 100644 --- a/test/modules/ssl/conftest.py +++ b/test/modules/ssl/conftest.py @@ -9,7 +9,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) def pytest_report_header(config, start_path): - env = SSLTestEnv() + env = SSLTestEnv(pytestconfig=config) return f"mod_ssl [apache: {env.get_httpd_version()}, mpm: {env.mpm_module}, {env.prefix}]" diff --git a/test/pyhttpd/env.py b/test/pyhttpd/env.py index 6441ff7be4..da5a34bfb4 100644 --- a/test/pyhttpd/env.py +++ b/test/pyhttpd/env.py @@ -450,6 +450,8 @@ class HttpdTestEnv: self._apachectl_stderr = None self._httpd_proc = None + self._apply_cli_overrides(pytestconfig) + self._dso_modules = self.config.get('httpd', 'dso_modules').split(' ') self._mpm_modules = self.config.get('httpd', 'mpm_modules').split(' ') self._mpm_module = f"mpm_{os.environ['MPM']}" if 'MPM' in os.environ else 'mpm_winnt' if self.isWindows else 'mpm_event' @@ -488,6 +490,62 @@ class HttpdTestEnv: self._nghttp_version = None self._current_test = None + def _apply_cli_overrides(self, pytestconfig): + """Override config.ini values with --httpd / --conf CLI options. + + config.ini is generated by the build system from config.ini.in and + is never rewritten. When --httpd or --conf are passed on the + command line the corresponding variables are overridden in memory. + """ + if pytestconfig is None: + return + httpd_path = pytestconfig.getoption("--httpd", default=None) + conf_path = pytestconfig.getoption("--conf", default=None) + if httpd_path: + httpd_path = os.path.abspath(httpd_path) + prefix = os.path.dirname(os.path.dirname(httpd_path)) + self._bin_dir = os.path.dirname(httpd_path) + self._prefix = prefix + self._libexec_dir = os.path.join(prefix, "modules") + HttpdTestEnv.LIBEXEC_DIR = self._libexec_dir + if self.isWindows: + self._apachectl = httpd_path + else: + ctl = os.path.join(self._bin_dir, "apachectl") + self._apachectl = ctl if os.path.isfile(ctl) else httpd_path + self._apxs = os.path.join(self._bin_dir, "apxs") + try: + p = subprocess.run([httpd_path, "-v"], + capture_output=True, text=True) + m = re.search(r"Apache/(\S+)", p.stdout) + if m: + self._httpd_ver = m.group(1) + except Exception: + pass + if conf_path: + conf_path = os.path.abspath(conf_path) + dso = [] + mpm = [] + try: + with open(conf_path) as f: + for line in f: + line = line.strip() + if line.startswith("#"): + continue + m = re.match(r"LoadModule\s+(\S+)_module", line) + if m: + name = m.group(1) + if name.startswith("mpm_"): + mpm.append(name) + else: + dso.append(name) + except Exception: + pass + if dso: + self.config.set('httpd', 'dso_modules', ' '.join(dso)) + if mpm: + self.config.set('httpd', 'mpm_modules', ' '.join(mpm)) + def add_httpd_conf(self, lines: List[str]): self._httpd_base_conf.extend(lines)