man-group / man-group/pytest-plugins

pytest-shutil 1.7.0: test_run_in_subprocess* tests failing on Python 2.7.15

Open
#141 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
597
Forks
89
PR merge metrics
No merged PRs in 30d

Description

I've got pretty much all the `test_run_in_subprocess*` tests failing in CPython 2.7.15 (they all pass or xfail in 3.6.6 on the same system). Most of the failures trace back to `os.dup2()` raising "`OSError: [Errno 9] Bad file descriptor`" in `_run_in_subprocess_redirect_stdout()`. This _seems to_ be related to the `fix_stdout` setting in pytest_shutil/run.py (conditionally set only on pre-3.x Python), so I suspect something is wrong in the specific codepath for handling that condition.

At first glance it looks like `stack2.callback(os.close, fd)` should be on `stack` rather than `stack2`, but changing that didn't fix this. Hardcoding `fix_stdout = False` gets those tests to pass in my setup, but there's obviously a legitimate reason for having that logic in the first place.

The one remaining test that doesn't trace back to that error fails with the following traceback:

```
______________________________________________________________________________________ test_run_in_subprocess_passes_stdout ______________________________________________________________________________________

@pytest.mark.xfail('sys.version_info >= (3, 0, 0)')
def test_run_in_subprocess_passes_stdout():
def fn(x):
import sys # @Reimport
sys.stdout.write(x)
guid = str(uuid4())
cmd = """from pytest_shutil.run import run_in_subprocess
run_in_subprocess(%r)(%r)
""" % (textwrap.dedent(inspect.getsource(fn)), guid)
with no_cov():
p = subprocess.Popen([sys.executable, '-c', cmd], stdout=subprocess.PIPE)
(out, _) = p.communicate()
> assert out == guid
E AssertionError: assert '' == '941d38df-2741-4de1-8ec0-1e5514af072a'
E + 941d38df-2741-4de1-8ec0-1e5514af072a
```
I can't help noticing this is marked as xfail on Python 3.x. Maybe the xfail mark is applicable to my Python 2.7.15 setup as well?

This is on a custom GNU/Linux 4.16.18 distro with glibc 2.28 on an AArch64 system.

(On a side note, I have a lot of pytest plugins installed, and I specifically have to disable the benchmark and checkdocs plugins to prevent spurious pytest failures. Disabling almost all of my other pytest plugins didn't help with this situation though.)

Contributor guide

No contributing guide indexed for this repository

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 with pytest_shutil/run.py and the test_run_in_subprocess* tests, reproducing the failures under CPython 2.7.15 on the reported GNU/Linux AArch64 environment. Trace the fix_stdout and stdout-redirection paths, including the os.dup2() and file-descriptor errors. Done means the affected tests pass or have the appropriate xfail behavior on Python 2.7.

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.