如何跳过Python 3.8.2 文件编码测试?

How to skip Python 3.8.2 test of files encoding?

我遇到了以下错误。当并非所有文件都 utf-8 可编码时,测试会在 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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

与此同时,完全相同的设置适用于 Python 3.7,如果我 运行 测试 poetry run pytest tests/my_tests.py

我正在使用:Python3.8.2,诗歌1.0.5

我该如何解决?这个错误很烦人,因为它在 CI.

中失败了

结果显示,问题与 poetrypython. 的任何版本无关 我将文件命名为 test.txt 并将其放在 tests/ 文件夹下.默认情况下,pytest 查找所有前缀为 test 的文件并验证它们的编码。由于 test.txtiso-8859-1 中,我遇到了一个与 UTF-8 相关的问题。

注意:

确保在使用 pytest 时不要使用 test 前缀命名文件。请注意,如果您决定使用前缀命名它们,它们应该是 UTF-8 编码的。