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

_collect_file_pytest7 requires UTF-8 encoding #9

Closed
mtelka opened this issue Oct 15, 2023 · 1 comment
Closed

_collect_file_pytest7 requires UTF-8 encoding #9

mtelka opened this issue Oct 15, 2023 · 1 comment
Assignees

Comments

@mtelka
Copy link

mtelka commented Oct 15, 2023

I tried to run tests for diff_cover==8.0.0 with pytest-perf==0.13.1 installed and the test collection failed:

________________________ ERROR collecting test session _________________________
/usr/lib/python3.9/vendor-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/usr/lib/python3.9/vendor-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/usr/lib/python3.9/vendor-packages/_pytest/main.py:749: in collect
    for x in self._collectfile(path):
/usr/lib/python3.9/vendor-packages/_pytest/main.py:602: in _collectfile
    return ihook.pytest_collect_file(file_path=fspath, parent=self)  # type: ignore[no-any-return]
/usr/lib/python3.9/vendor-packages/_pytest/config/compat.py:66: in fixed_hook
    return hook(**kw)
/usr/lib/python3.9/vendor-packages/pluggy/_hooks.py:493: in __call__
    return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
/usr/lib/python3.9/vendor-packages/pluggy/_manager.py:115: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
/usr/lib/python3.9/vendor-packages/pytest_perf/plugin.py:33: in _collect_file_pytest7
    if file_path.suffix == '.py' and 'pytest_perf' in file_path.read_text(
/usr/lib/python3.9/pathlib.py:1267: in read_text
    return f.read()
/usr/lib/python3.9/codecs.py:322: in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
E   UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 72: invalid continuation byte

The failure is because the diff_cover-8.0.0/tests/fixtures/snippet_8859.py file is not in UTF-8 but _collect_file_pytest7 expects that all .py files are encoded in UTF-8.

The solution (or workaround) for the problem is obvious: uninstall or disable pytest-perf while running tests for diff_cover.

Anyway, I'm reporting this here for consideration to make pytest-perf more tolerant about file encodings. If that's not possible or desirable or whatever feel free to close this bug.

Thank you.

@jaraco jaraco self-assigned this Jan 28, 2024
@jaraco
Copy link
Owner

jaraco commented Jan 28, 2024

Agreed - it should be tolerant of alternate encodings.

@jaraco jaraco closed this as completed in e827535 Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants