Use mock.patch to avoid mutating global state outside the test.
@@ -6,7 +6,7 @@ import re
import platform
import tempfile
import urllib.parse
-import http.client
+import unittest.mock
from http.client import HTTPConnection
import pytest
@@ -399,8 +399,12 @@ class StaticTest(helper.CPWebCase):
self.assertStatus(404)
self.assertInBody("I couldn't find that thing")
+ @unittest.mock.patch(
+ 'http.client._contains_disallowed_url_pchar_re',
+ re.compile(r'[\n]'),
+ create=True,
+ )
def test_null_bytes(self):
- http.client._contains_disallowed_url_pchar_re = re.compile(r'[\n]')
self.getPage('/static/\x00')
self.assertStatus('404 Not Found')
