pytest-dev / pytest-dev/pytest

Pytest will not issue PytestAssertRewriteWarning when __pycache__ is used

Open
#8,835 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: rewrite type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

  • description:

When a test contains an always true boolean there is a warning that the assert is always true:

: PytestAssertRewriteWarning: assertion is always true, perhaps remove parentheses?

This is as expected for the given example.

When the test is re run (using the cache generated in the first run) there is no warning given, this means that they can be missed and the test appears to pass.

Setting environment variable

PYTHONDONTWRITEBYTECODE=1

and invalidating/deleting pycache allows the warning to reappear

  • OS affected = all

  • pytest version = 6.2.0, 6.2.4

  • pip list

Package Version


astroid 2.4.2
attrs 20.3.0
boto3 1.16.47
botocore 1.19.63
certifi 2020.12.5
chardet 4.0.0
h5py 3.2.1
idna 2.10
iniconfig 1.1.1
isort 5.7.0
jmespath 0.10.0
lazy-object-proxy 1.4.3
mccabe 0.6.1
more-itertools 8.6.0
numpy 1.20.3
packaging 20.9
pip 21.1.1
pluggy 0.13.1
py 1.10.0
pylint 2.6.2
pyparsing 2.4.7
pytest 6.2.0
python-dateutil 2.8.1
pytz 2021.1
requests 2.25.1
s3transfer 0.3.4
setuptools 51.1.2
six 1.15.0
toml 0.10.2
urllib3 1.26.3
wheel 0.36.2
wrapt 1.12.1

minimal example:

def test_this_warns(): assert (1 == 2, "you will never read this")

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

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

Run the minimal test example twice with normal bytecode caching enabled, then repeat after deleting pycache or setting PYTHONDONTWRITEBYTECODE=1. Compare the PytestAssertRewriteWarning output between runs and trace the assertion-rewriting cache path. Done means the warning is issued consistently when cached bytecode is used.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.