fix tests failing with server name warnings
Before adoption: this commit came in with the history the project adopted, so no landing records it.
After pallets/werkzeug#1577, mismatched configured and real server names will show a warning in addition to raising 404. This caused tests that did this deliberately to fail. This patch removes the pytest fixture we were using to fail on warnings, instead using the standard `-Werror` option. This speeds up the tests by ~3x.
authored by David Lord · committed by David Lord · parent 6369537 · Browse files · 5 files·+36 added−62 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+36 added−62 removed
- tests:+34 added−60 removed
- other:+2 added−2 removed
Provenance
- Commit
dbd4520- Tree
0605890- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
6369537
5 files changed+36 added−62 removed
modified:tests/conftest.py-7 removed
194 unmodified lines195 def inner(name):196 request.addfinalizer(lambda: sys.modules.pop(name, None))197 198 return inner199-200-201-@pytest.fixture(autouse=True)202-def catch_deprecation_warnings(recwarn):203- yield204- gc.collect()205- assert not recwarn.list, '\n'.join(str(w.message) for w in recwarn.list)modified:tests/test_basic.py+31 added-45 removed
1440 unmodified lines1441 assert repr(flask.g) == '<LocalProxy unbound>'1442 assert not flask.g1443 1444 1445-def test_test_app_proper_environ():1445+def test_server_name_subdomain():1446 app = flask.Flask(__name__, subdomain_matching=True)1447- app.config.update(1448- SERVER_NAME='localhost.localdomain:5000'1449- )1447 client = app.test_client()1448 1452- @app.route('/')1449+ @app.route("/")1450 def index():1454- return 'Foo'1451+ return "default"1452 1456- @app.route('/', subdomain='foo')1453+ @app.route("/", subdomain="foo")1454 def subdomain():1458- return 'Foo SubDomain'1455+ return "subdomain"1456 1457+ app.config["SERVER_NAME"] = "dev.local:5000"1460- rv = client.get('/')1461- assert rv.data == b'Foo'1458+ rv = client.get("/")1459+ assert rv.data == b"default"1460 1463- rv = client.get('/', 'http://localhost.localdomain:5000')1464- assert rv.data == b'Foo'1461+ rv = client.get("/", "http://dev.local:5000")1462+ assert rv.data == b"default"1463 1466- rv = client.get('/', 'https://localhost.localdomain:5000')1467- assert rv.data == b'Foo'1464+ rv = client.get("/", "https://dev.local:5000")1465+ assert rv.data == b"default"1466 1469- app.config.update(SERVER_NAME='localhost.localdomain')1470- rv = client.get('/', 'https://localhost.localdomain')1471- assert rv.data == b'Foo'1467+ app.config["SERVER_NAME"] = "dev.local:443"1468+ rv = client.get("/", "https://dev.local")1469 1473- try:1474- app.config.update(SERVER_NAME='localhost.localdomain:443')1475- rv = client.get('/', 'https://localhost.localdomain')1476- # Werkzeug 0.81477- assert rv.status_code == 4041478- except ValueError as e:1479- # Werkzeug 0.71480- assert str(e) == (1481- "the server name provided "1482- "('localhost.localdomain:443') does not match the "1483- "server name from the WSGI environment ('localhost.localdomain')"1484- )1470+ # Werkzeug 1.0 fixes matching https scheme with 443 port1471+ if rv.status_code != 404:1472+ assert rv.data == b"default"1473 1486- try:1487- app.config.update(SERVER_NAME='localhost.localdomain')1488- rv = client.get('/', 'http://foo.localhost')1489- # Werkzeug 0.81474+ app.config["SERVER_NAME"] = "dev.local"1475+ rv = client.get("/", "https://dev.local")1476+ assert rv.data == b"default"1477+1478+ # suppress Werkzeug 1.0 warning about name mismatch1479+ with pytest.warns(None):1480+ rv = client.get("/", "http://foo.localhost")1481 assert rv.status_code == 4041491- except ValueError as e:1492- # Werkzeug 0.71493- assert str(e) == (1494- "the server name provided "1495- "('localhost.localdomain') does not match the "1496- "server name from the WSGI environment ('foo.localhost')"1497- )1482 1499- rv = client.get('/', 'http://foo.localhost.localdomain')1500- assert rv.data == b'Foo SubDomain'1483+ rv = client.get("/", "http://foo.dev.local")1484+ assert rv.data == b"subdomain"1485 1486 1487 def test_exception_propagation(app, client):1488 def apprunner(config_key):348 unmodified lines1837 @app.route('/')1838 def index():1839 return '', 2041840 1841+ # suppress Werkzeug 0.15 warning about name mismatch1842+ with pytest.warns(None):1857- # ip address can't match name1858- rv = client.get('/', 'http://127.0.0.1:3000/')1859- assert rv.status_code == 404 if matching else 2041843+ # ip address can't match name1844+ rv = client.get('/', 'http://127.0.0.1:3000/')1845+ assert rv.status_code == 404 if matching else 2041846 1847 # allow all subdomains if matching is disabled1848 rv = client.get('/', 'http://www.localhost.localdomain:3000/')1849 assert rv.status_code == 404 if matching else 20499 unmodified linesmodified:tests/test_helpers.py+1 added-1 removed
441 unmodified lines442 rv.direct_passthrough = False443 assert rv.data == f.read()444 rv.close()445 446- def test_send_file_xsendfile(self, app, req_ctx, catch_deprecation_warnings):446+ def test_send_file_xsendfile(self, app, req_ctx):447 app.use_x_sendfile = True448 rv = flask.send_file('static/index.html')449 assert rv.direct_passthrough450 assert 'x-sendfile' in rv.headers506 unmodified linesmodified:tests/test_reqctx.py+2 added-7 removed
86 unmodified lines87 with app.test_request_context('/'):88 assert flask.url_for('sub', _external=True) == \89 'http://foo.localhost.localdomain:5000/'90 91- try:91+ # suppress Werkzeug 0.15 warning about name mismatch92+ with pytest.warns(None):93 with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):94 pass94- except ValueError as e:95- assert str(e) == (96- "the server name provided "97- "('localhost.localdomain:5000') does not match the "98- "server name from the WSGI environment ('localhost')"99- )95 96 app.config.update(SERVER_NAME='localhost')97 with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost'}):98 pass124 unmodified linesmodified:tox.ini+2 added-2 removed
31 unmodified lines32 pip install -q -e examples/tutorial[test]33 pip install -q -e examples/javascript[test]34 35 # pytest-cov doesn't seem to play nice with -p36- coverage run -p -m pytest --tb=short {posargs:tests examples}36+ coverage run -p -m pytest --tb=short -Werror {posargs:tests examples}37 38 [testenv:nightly]39 # courtesy Python nightly test, don't fail the build in CI40 ignore_outcome = true41 commands =42 pip install -q -e examples/tutorial[test]43 pip install -q -e examples/javascript[test]44- coverage run -p -m pytest --tb=short --junitxml=test-results.xml {posargs:tests examples}44+ coverage run -p -m pytest --tb=short -Werror --junitxml=test-results.xml {posargs:tests examples}45 46 [testenv:stylecheck]47 deps = pre-commit48 skip_install = true26 unmodified lines