pytest-dev / pytest-dev/pytest-bdd
Step file generated from powershell throws error on collection - not UTF-8 encoded
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 251
- Avg merge
- 43m
- Merged PRs (30d)
- 2
Description
Generate in powershell with: with: pytest-bdd generate features/installer.feature > installer_step_definitions/test_installer_steps.py
Run with: pytest
OBS: During test collection error occurs as below. The same file test_installer_steps.py created in VS code and the same code pasted from Notepad++ works.
Note: If I create file by hand and overwrite it by auto generated file this happens:
Original encoding
When I convert to UTF-8 it works fine or if I run in cmd
VS Code encoding is UTF-8
ENV:
VS Code
Python 3.12
packages
Package Version
colorama 0.4.6
iniconfig 2.0.0
Mako 1.3.0
MarkupSafe 2.1.3
packaging 23.2
parse 1.19.1
parse-type 0.6.2
pip 23.3.1
pluggy 1.3.0
pytest 7.4.3
pytest-bdd 7.0.0
six 1.16.0
typing_extensions 4.8.0
.venv\Lib\site-packages_pytest\assertion\rewrite.py:359:
source = b'\xff\xfe"\x00"\x00"\x00I\x00n\x00s\x00t\x00a\x00l\x00l\x00e\x00r\x00 \x00f\x00e\x00a\x00t\x00u\x00r\x00e\x00 \x00t\x...\x00o\x00t\x00I\x00m\x00p\x00l\x00e\x00m\x00e\x00n\x00t\x00e\x00d\x00E\x00r\x00r\x00o\x00r\x00\r\x00\n\x00\r\x00\n\x00'
filename = 'C:\\Users\\vsypniewski-tom\\source\\repos\\xcd-bdd\\installer_step_definitions\\test_installer_steps.py', mode = 'exec'
def parse(source, filename='<unknown>', mode='exec', *,
type_comments=False, feature_version=None):
"""
Parse the source into an AST node.
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
Pass type_comments=True to get back type comments where the syntax allows.
"""
flags = PyCF_ONLY_AST
if type_comments:
flags |= PyCF_TYPE_COMMENTS
if feature_version is None:
feature_version = -1
elif isinstance(feature_version, tuple):
major, minor = feature_version # Should be a 2-tuple.
if major != 3:
raise ValueError(f"Unsupported major version: {major}")
feature_version = minor
# Else it should be an int giving the minor version for 3.x.
> return compile(source, filename, mode, flags,
_feature_version=feature_version)
E SyntaxError: source code string cannot contain null bytes
..\..\..\AppData\Local\Programs\Python\Python312\Lib\ast.py:52: SyntaxError
The above exception was the direct cause of the following exception:
cls = <class '_pytest.runner.CallInfo'>, func = <function pytest_make_collect_report.<locals>.<lambda> at 0x000002367EB0F4C0>, when = 'collect', reraise = None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing pytest-bdd generate features/installer.feature > installer_step_definitions/test_installer_steps.py in PowerShell, then run pytest and inspect the generated file's encoding. Compare the PowerShell output with the cmd and manually converted versions; done means the generated step file is accepted during pytest collection without null-byte or encoding errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100