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

File encodings can not be defined when opening files for content tests #161

Closed
fabianegli opened this issue Dec 20, 2022 · 5 comments · Fixed by #163
Closed

File encodings can not be defined when opening files for content tests #161

fabianegli opened this issue Dec 20, 2022 · 5 comments · Fixed by #163

Comments

@fabianegli
Copy link

fabianegli commented Dec 20, 2022

It would probably be nice if one could pass file encodings to the tests to make sure the files are read with the right encoding.

The way it is set up now open will infer the encoding with locale.getpreferredencoding(False). However, if a process produces a file in another encoding, tests will inadvertently break.

with file_open(mode='rt') as file_handler: # type: ignore # mypy goes crazy here otherwise # noqa: E501

@rhpvorderman
Copy link
Member

Another good catch. Currently our use case for pytest-workflow is only on linux where everything is UTF-8 encoded. For frequent platform-hoppers this might be an issue. I will put this on the backlog until somebody reports an actual crash. . Does this cause errors for you at the moment?

@fabianegli
Copy link
Author

I can imagine pytest-workflow to be useful in a multi-language setting and there someone might have to work with files in various encodings.

Having said that the issue arose in a context where a control character popped up in a log file that was tested with a contains clause. Because the control character ('\x14') can not be validly decoded in utf-8, this lead to the test failure although the failing decoding was on a later line that the contains string.

@rhpvorderman
Copy link
Member

Okay. I will have a look at it. I want to maintain the current behavior when no encoding is given, but I think it should be easy enough to add an optional encoding keyword to the yaml.

@rhpvorderman
Copy link
Member

The latest development version should have the fix. Can you check if the problem still remains?

@rhpvorderman
Copy link
Member

Fixed in the newest release 2.0.0.

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

Successfully merging a pull request may close this issue.

2 participants