How to skip Python 3.8.2 test of files encoding?

Viewed 334

I bumped into the following bug. When not all files are utf-8 encodable, tests fail on poetry run pytest -v.

============================================================== ERRORS =============================================================== ____________________________________________ ERROR collecting tests/anonymized/test.txt _____________________________________________ .venv/lib/python3.8/site-packages/py/_path/common.py:171: in read_text return f.read() ../../../.pyenv/versions/3.8.2/lib/python3.8/codecs.py:322: in decode (result, consumed) = self._buffer_decode(data, self.errors, final) E UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf8 in position 380: invalid start byte ====================================================== short test summary info ====================================================== ERROR tests/anonymized/test.txt - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf8 in position 380: invalid start byte !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

In the meantime, exactly the same setup worked with Python 3.7, and if I run tests with poetry run pytest tests/my_tests.py.

I am using: Python 3.8.2, poetry 1.0.5

How can I fix it? This bug is annoying as it fails in CI.

1 Answers

As it came out, the issue was not related to any version of poetry or python. I named the file test.txt and put it under the tests/ folder. By default, pytest finds all files prefixed with test and verifies their encoding. As the test.txt was in iso-8859-1, I got a UTF-8 related issue.

NOTE:

Make sure that you don't name files with the test prefix when using pytest. Beware that if you decide to name them with the prefix, they should be UTF-8 encoded.

Related