The Wayback Machine - https://web.archive.org/web/20201102192752/https://github.com/encode/django-rest-framework/pull/6638
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 BytesWarning in test_schemas.py #6638

Merged
merged 1 commit into from May 1, 2019
Merged

Conversation

@jdufresne
Copy link
Contributor

@jdufresne jdufresne commented May 1, 2019

When Python is run with the -b command line argument, the following
warning was previously emitted:

tests/test_schemas.py::test_schema_handles_exception
.../django-rest-framework/tests/test_schemas.py:1361: BytesWarning: str() on a bytes instance
assert "You do not have permission to perform this action." in str(response.content)

To fix this warning decode the bytes with an explicit encoding.

For details on the -b command line argument, see:

https://docs.python.org/3/using/cmdline.html#cmdoption-b

@rpkilby
Copy link
Member

@rpkilby rpkilby commented May 1, 2019

Would it make sense to just test with a byte string instead of decoding the response content?

assert b"You do not have permission to perform this action." in response.content
@jdufresne
Copy link
Contributor Author

@jdufresne jdufresne commented May 1, 2019

Yup. Either way works as an effective assert.

@jdufresne jdufresne force-pushed the jdufresne:bytes-warn branch from 1479911 to b530f8e May 1, 2019
When Python is run with the -b command line argument, the following
warning was previously emitted:

    tests/test_schemas.py::test_schema_handles_exception
      .../django-rest-framework/tests/test_schemas.py:1361: BytesWarning: str() on a bytes instance
        assert "You do not have permission to perform this action." in str(response.content)

To fix this warning decode the bytes with an explicit encoding.

For details on the -b command line argument, see:

https://docs.python.org/3/using/cmdline.html#cmdoption-b
@jdufresne jdufresne force-pushed the jdufresne:bytes-warn branch from b530f8e to c231bb3 May 1, 2019
@jdufresne
Copy link
Contributor Author

@jdufresne jdufresne commented May 1, 2019

Switched to the bytes literal approach.

@rpkilby
rpkilby approved these changes May 1, 2019
Copy link
Member

@rpkilby rpkilby left a comment

👌

@rpkilby rpkilby merged commit f669395 into encode:master May 1, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
terencehonles added a commit to terencehonles/django-rest-framework that referenced this pull request Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.