Add warnings when calling deprecated method (#596)
* Add test * To run the workflow * Fix import * Format * Add warning * Fix indentation * Test deprecated method * More test * Format * Add import if needed --------- Co-authored-by: Adrien Vannson <adrien.vannson@gardacp.com>
This commit is contained in:
@@ -12,3 +12,10 @@ message Message {
|
||||
option deprecated = true;
|
||||
string value = 1;
|
||||
}
|
||||
|
||||
message Empty {}
|
||||
|
||||
service TestService {
|
||||
rpc func(Empty) returns (Empty);
|
||||
rpc deprecated_func(Empty) returns (Empty) { option deprecated = true; };
|
||||
}
|
||||
|
@@ -2,9 +2,12 @@ import warnings
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.mocks import MockChannel
|
||||
from tests.output_betterproto.deprecated import (
|
||||
Empty,
|
||||
Message,
|
||||
Test,
|
||||
TestServiceStub,
|
||||
)
|
||||
|
||||
|
||||
@@ -43,3 +46,19 @@ def test_message_with_deprecated_field_not_set_default(message):
|
||||
_ = Test(value=10).message
|
||||
|
||||
assert not record
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_service_with_deprecated_method():
|
||||
stub = TestServiceStub(MockChannel([Empty(), Empty()]))
|
||||
|
||||
with pytest.warns(DeprecationWarning) as record:
|
||||
await stub.deprecated_func(Empty())
|
||||
|
||||
assert len(record) == 1
|
||||
assert str(record[0].message) == f"TestService.deprecated_func is deprecated"
|
||||
|
||||
with pytest.warns(None) as record:
|
||||
await stub.func(Empty())
|
||||
|
||||
assert not record
|
||||
|
Reference in New Issue
Block a user