Skip to content

Commit

Permalink
Tests: mock dns queries to avoid flaky tests (#11821)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Dec 4, 2024
1 parent ca860b8 commit c072cdd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions readthedocs/rtd_tests/tests/test_domains.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from unittest import mock

import dns.resolver
from django.conf import settings
from django.test import TestCase, override_settings
from django_dynamic_fixture import get
Expand Down Expand Up @@ -28,6 +31,12 @@ def test_save_parsing(self):
self.assertEqual(domain.domain, "www.google.com")


# We are using random domain names to test the form validation,
# so we are mocking the DNS resolver to avoid making real DNS queries.
@mock.patch(
"readthedocs.projects.forms.dns.resolver.resolve",
new=mock.MagicMock(side_effect=dns.resolver.NoAnswer),
)
class FormTests(TestCase):
def setUp(self):
self.project = get(Project, slug="kong")
Expand Down

0 comments on commit c072cdd

Please sign in to comment.