Skip to content
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
4 changes: 2 additions & 2 deletions rest_framework/schemas/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def should_include_endpoint(self, path, callback):
return False # Ignore anything except REST framework views.

if hasattr(callback.cls, 'exclude_from_schema'):
fmt = ("{}. The `APIView.exclude_from_schema` is pending deprecation. "
"Set `schema = None` instead")
fmt = ("The `{}.exclude_from_schema` is pending deprecation. "
"Set `schema = None` instead.")
msg = fmt.format(callback.cls.__name__)
warnings.warn(msg, PendingDeprecationWarning)
if getattr(callback.cls, 'exclude_from_schema', False):
Expand Down
16 changes: 14 additions & 2 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,11 +690,17 @@ def test_should_include_endpoint_excludes_correctly(self):
assert should_include == expected

def test_deprecations(self):
with pytest.warns(PendingDeprecationWarning):
with pytest.warns(PendingDeprecationWarning) as record:
@api_view(["GET"], exclude_from_schema=True)
def view(request):
pass

assert len(record) == 1
assert str(record[0].message) == (
"The `exclude_from_schema` argument to `api_view` is pending "
"deprecation. Use the `schema` decorator instead, passing `None`."
)

class OldFashionedExcludedView(APIView):
exclude_from_schema = True

Expand All @@ -706,5 +712,11 @@ def get(self, request, *args, **kwargs):
]

inspector = EndpointEnumerator(patterns)
with pytest.warns(PendingDeprecationWarning):
with pytest.warns(PendingDeprecationWarning) as record:
inspector.get_api_endpoints()

assert len(record) == 1
assert str(record[0].message) == (
"The `OldFashionedExcludedView.exclude_from_schema` is "
"pending deprecation. Set `schema = None` instead."
)