-
-
Notifications
You must be signed in to change notification settings - Fork 457
Description
Hi,
First of all, thanks for the great library!
Describe the bug
I have a test that spawns a child process with pexpect and runs my application. Then, it checks whether some output is displayed and interacts with the program in the child process. The test looks like this.
def test_pdb_interaction_capturing_simple(tmp_path):
source = """
import pdb
def task_1():
i = 0
print("hello17")
pdb.set_trace()
i == 1
assert 0
"""
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
child = pexpect.spawn(f"pytask {tmp_path.as_posix()}")
child.expect(r"task_1\(\)")
child.expect("i == 1") # The error happens here.
...
You can think of the task function defined in the string as a test function from pytest. Like pytest, my program would also stop at pdb.set_trace
and allow the user to debug the function.
When I run the test with the --cov
option from pytest-cov and coverage==6.4.1, the test fails after the statement with pdb.set_trace
on Ubuntu and macOS. It seems like the content i == 1
is not displayed in the child process, but it is hard to tell since pexpect is hard to debug.
The test succeeds when I remove the --cov
option. The test is also OK on Ubuntu and MacOS with coverage<=6.4.0.
To Reproduce
I reproduced and fixed the error by pinning coverage in pytask-dev/pytask#283.
- Create a conda environment from
environment.yml
. (If it helps reproduce the bug, I can add a requirement.txt.) - Run the failing tests with
pytest tests/test_debugging.py --cov=src
. - The tests will fail on Linux and macOS with Python 3.7-10 and coverage==6.4.1.
Expected behavior
The tests should run fine as before.
Additional context
Since my package is a fork of pytest and very similar regarding this feature, I would not be surprised if they encounter the same issue. I saw some failing jobs in their PRs, which seem to have the same problem: https://github.com/pytest-dev/pytest/runs/6852766697?check_suite_focus=true#step:6:201.