pytest-dev / pytest-dev/pytest

Syntax error in test file makes pytest exit with exit code 2

Open
#4,603 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: config type: enhancement
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

  1. Create a file named test_syntax_error.py with content
def x:
    pass
  1. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.