Skip to content

Commit 1596b25

Browse files
committed
tests: test more reliably if port 25 is reachable
1 parent 1f5b2e9 commit 1596b25

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cmdeploy/src/cmdeploy/tests/online/test_1_basic.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import smtplib
33
import subprocess
4+
import socket
45

56
import pytest
67

@@ -118,14 +119,19 @@ def test_authenticated_from(cmsetup, maildata):
118119

119120
@pytest.mark.parametrize("from_addr", ["[email protected]", "[email protected]"])
120121
def test_reject_missing_dkim(cmsetup, maildata, from_addr):
122+
domain = cmsetup.maildomain
123+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
124+
sock.settimeout(10)
125+
try:
126+
sock.connect((domain, 25))
127+
except socket.timeout:
128+
pytest.skip(f"port 25 not reachable for {domain}")
129+
121130
recipient = cmsetup.gen_users(1)[0]
122131
msg = maildata(
123132
"encrypted.eml", from_addr=from_addr, to_addr=recipient.addr
124133
).as_string()
125-
try:
126-
conn = smtplib.SMTP(cmsetup.maildomain, 25, timeout=10)
127-
except TimeoutError:
128-
pytest.skip(f"port 25 not reachable for {cmsetup.maildomain}")
134+
conn = smtplib.SMTP(cmsetup.maildomain, 25, timeout=10)
129135

130136
with conn as s:
131137
with pytest.raises(smtplib.SMTPDataError, match="No valid DKIM signature"):

0 commit comments

Comments
 (0)