Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated usage of pytest #235

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ class TestDeprecatedTimeoutKwarg:

This class should be removed when the socket_timeout argument is removed.
"""
def setup(self):
def setup_method(self):
# Create and apply a fresh patch for each test.
self.async_sock = patch(
'thriftpy2.contrib.aio.rpc.TAsyncSocket',
side_effect=RuntimeError,
).__enter__()

def teardown_(self):
def teardown_method(self):
self.async_sock.__exit__() # Clean up patch

@pytest.mark.asyncio
Expand All @@ -348,9 +348,13 @@ async def _make_client(warning=None, **kwargs):
is emitted (if any) and that the patch is properly applied by
consuming the RuntimeError.
"""
with pytest.warns(warning),\
pytest.raises(RuntimeError): # Consume error
await make_aio_client(addressbook.AddressBookService, **kwargs)
if warning:
with pytest.warns(warning),\
pytest.raises(RuntimeError): # Consume error
await make_aio_client(addressbook.AddressBookService, **kwargs)
else:
with pytest.raises(RuntimeError): # Consume error
await make_aio_client(addressbook.AddressBookService, **kwargs)

def _given_timeout(self):
"""Get the timeout provided to TAsyncSocket."""
Expand Down
5 changes: 2 additions & 3 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,8 @@ def test_exception_iwth_ssl():

def test_client_timeout():
with pytest.raises(socket.timeout):
with pytest.warns(UserWarning): # Deprecated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This UserWarning is never been raised, but the older version of pytest will ignore the failure when it't in a with pytest.raises(...) context.

So we should just remove it.

with client(timeout=500) as c:
c.sleep(1000)
with client(timeout=500) as c:
c.sleep(1000)


def test_client_socket_timeout():
Expand Down
Loading