pytest-dev / pytest-dev/pytest
Syntax error in test file makes pytest exit with exit code 2
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Ubuntu 18.04
pytest-4.0.2
python 2.7 and 3.6
Description
Having a test file with syntax error or import error results in pytest exiting with exitcode 2.
How to reproduce
- Create a file named
test_syntax_error.pywith content
def x:
pass
- Run pytest and print exit code
pytest test_syntax_error.py; echo $?
Expected
Probably worth a new exitcode as it doesn't really fit into those 5 documented
Actual
Exits with code 2, which stands for "Test execution was interrupted by the user"
Similarly, a file with content import non_existent will have the same effect.
This issue is similar to https://github.com/pytest-dev/pytest/issues/2832 and also
https://github.com/pytest-dev/pytest/issues/2950, but still I hope this will be useful for reference and example.
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 the issue with the provided test_syntax_error.py example and the pytest command, then compare the resulting exit code with the documented exit codes. Trace how syntax and import errors are classified and determine the intended distinct outcome. Done means the behavior and documentation clearly distinguish these errors from user interruption, with tests covering both examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100