From 2a5dc570d8ef27f8864dfdad04a46bb54bacdb7a Mon Sep 17 00:00:00 2001 From: Alexander Macdonald Date: Thu, 8 Feb 2024 17:38:38 -0800 Subject: [PATCH] rename a shadowed test and re-enable F811 to catch future cases (#8139) (#8147) (cherry picked from commit 3c0f1eb29d3512419ea65e7cdeb61ba3f3496f00) --- CHANGES/8139.contrib.rst | 1 + setup.cfg | 2 +- tests/test_resolver.py | 26 -------------------------- tests/test_urldispatch.py | 16 +++++++++------- 4 files changed, 11 insertions(+), 34 deletions(-) create mode 100644 CHANGES/8139.contrib.rst diff --git a/CHANGES/8139.contrib.rst b/CHANGES/8139.contrib.rst new file mode 100644 index 00000000000..fd743e70f4a --- /dev/null +++ b/CHANGES/8139.contrib.rst @@ -0,0 +1 @@ +Two definitions for "test_invalid_route_name" existed, only one was being run. Refactored them into a single parameterized test. Enabled lint rule to prevent regression. -- by :user:`alexmac`. diff --git a/setup.cfg b/setup.cfg index c0515be8eeb..83da3961014 100644 --- a/setup.cfg +++ b/setup.cfg @@ -86,7 +86,7 @@ zip_ok = false [flake8] extend-select = B950 # TODO: don't disable D*, fix up issues instead -ignore = N801,N802,N803,E203,E226,E305,W504,E252,E301,E302,E501,E704,W503,W504,F811,D1,D4 +ignore = N801,N802,N803,E203,E226,E305,W504,E252,E301,E302,E501,E704,W503,W504,D1,D4 max-line-length = 88 per-file-ignores = # I900: Shouldn't appear in requirements for examples. diff --git a/tests/test_resolver.py b/tests/test_resolver.py index 6140e385cc1..1b389f3601b 100644 --- a/tests/test_resolver.py +++ b/tests/test_resolver.py @@ -179,33 +179,7 @@ async def unknown_addrinfo(*args: Any, **kwargs: Any) -> List[Any]: async def test_close_for_threaded_resolver(loop) -> None: - resolver = ThreadedResolver(loop=loop) - await resolver.close() - - -async def test_threaded_negative_lookup_with_unknown_result() -> None: - loop = Mock() - - # If compile CPython with `--disable-ipv6` option, - # we will get an (int, bytes) tuple, instead of a Exception. - async def unknown_addrinfo(*args: Any, **kwargs: Any) -> List[Any]: - return [ - ( - socket.AF_INET6, - socket.SOCK_STREAM, - 6, - "", - (10, b"\x01\xbb\x00\x00\x00\x00*\x04NB\x00\x1a\x00\x00"), - ) - ] - - loop.getaddrinfo = unknown_addrinfo resolver = ThreadedResolver() - resolver._loop = loop - with patch("socket.has_ipv6", False): - res = await resolver.resolve("www.python.org") - assert len(res) == 0 - await resolver.close() diff --git a/tests/test_urldispatch.py b/tests/test_urldispatch.py index 7c4941f9b3c..4f3abb8bcd7 100644 --- a/tests/test_urldispatch.py +++ b/tests/test_urldispatch.py @@ -1130,14 +1130,16 @@ def test_subapp_iter(app) -> None: assert list(resource) == [r1, r2] -def test_invalid_route_name(router) -> None: - with pytest.raises(ValueError): - router.add_get("/", make_handler(), name="invalid name") - - -def test_invalid_route_name(router) -> None: +@pytest.mark.parametrize( + "route_name", + ( + "invalid name", + "class", + ), +) +def test_invalid_route_name(router, route_name: str) -> None: with pytest.raises(ValueError): - router.add_get("/", make_handler(), name="class") # identifier + router.add_get("/", make_handler(), name=route_name) def test_frozen_router(router) -> None: