Speed up mac tests using various strategies (#10419)

Alternative to https://github.com/certbot/certbot/pull/10408/ and
https://github.com/certbot/certbot/pull/10415/ that fixes production
code for account meta and puts autouse fixtures in certbot and acme
tests. Overrides all `time.sleep` calls while we're at it.

Fixes the production code where it's simple/clean, and fixes the tests
for HTTPServer-based code because we just don't have that many mac users
using standalone.
This commit is contained in:
ohemorange 2025-08-14 09:58:06 -07:00 committed by GitHub
parent bd796deaa3
commit 801894c7da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 2 deletions

View file

@ -0,0 +1,16 @@
from unittest import mock
import pytest
# This avoids a bug on mac where getfqdn errors after a long timeout.
# See https://bugs.python.org/issue35164
# and discussion at https://github.com/certbot/certbot/pull/10408
@pytest.fixture(autouse=True)
def mock_getfqdn():
with mock.patch("socket.getfqdn", return_value="server_name") as mocked:
yield mocked
@pytest.fixture(autouse=True)
def mock_sleep():
with mock.patch("time.sleep") as mocked:
yield mocked

View file

@ -62,7 +62,7 @@ class Account:
self.meta = self.Meta(
# pyrfc3339 drops microseconds, make sure __eq__ is sane
creation_dt=datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0),
creation_host=socket.getfqdn(),
creation_host=socket.gethostname(),
register_to_eff=None) if meta is None else meta
# try MD5, else use MD5 in non-security mode (e.g. for FIPS systems / RHEL)

View file

@ -31,7 +31,7 @@ class AccountTest(unittest.TestCase):
self.regr.__repr__ = mock.MagicMock(return_value="i_am_a_regr")
with mock.patch("certbot._internal.account.socket") as mock_socket:
mock_socket.getfqdn.return_value = "test.certbot.org"
mock_socket.gethostname.return_value = "test.certbot.org"
with mock.patch("certbot._internal.account.datetime") as mock_dt:
mock_dt.datetime.now.return_value = self.meta.creation_dt
self.acc_no_meta = Account(self.regr, KEY)

View file

@ -0,0 +1,16 @@
from unittest import mock
import pytest
# This avoids a bug on mac where getfqdn errors after a long timeout.
# See https://bugs.python.org/issue35164
# and discussion at https://github.com/certbot/certbot/pull/10408
@pytest.fixture(autouse=True)
def mock_getfqdn():
with mock.patch("socket.getfqdn", return_value="server_name") as mocked:
yield mocked
@pytest.fixture(autouse=True)
def mock_sleep():
with mock.patch("time.sleep") as mocked:
yield mocked