title: Running a subprocess fails when not using pytest no-capture
body: <h2>Setup</h2>
  <p>I've simplified the problem to the core:</p>
  <ol>
  <li>Having pytest installed</li>
  </ol>
  <pre class="lang-sh prettyprint-override"><code>pip install pytest==5.4.3
  </code></pre>
  <ol start="2">
  <li>Having a shell script</li>
  </ol>
  <pre class="lang-sh prettyprint-override"><code># has-stdin.sh
  
  # Detect stdin
  if [[ ! -t 0 ]]; then
      echo &quot;yes&quot;
  else
      echo &quot;no&quot;
  fi
  </code></pre>
  <ol start="3">
  <li>Having a Python test</li>
  </ol>
  <pre class="lang-py prettyprint-override"><code># test.py
  
  import subprocess
  import unittest
  
  
  class TestCase(unittest.TestCase):
  
      def test(self):
          process = subprocess.run(
              [&quot;sh&quot;, &quot;./has-stdin.sh&quot;],
              stderr=subprocess.PIPE,
              stdout=subprocess.PIPE,
              check=True,
              shell=False
          )
          assert process.stdout.decode(&quot;utf-8&quot;) == &quot;no\n&quot;
  
  </code></pre>
  <hr />
  <h2>Testing</h2>
  <p>✅ Script works in a bash shell</p>
  <pre><code>$ sh ./has-stdin.sh
  no
  </code></pre>
  <pre><code>$ echo '' | sh ./has-stdin.sh
  yes
  </code></pre>
  <pre><code>$ sh ./has-stdin.sh &lt;&lt;&lt; ''
  yes
  </code></pre>
  <p>✅ Runs successfully with <code>-s</code> (e.g. <code>--capture=no</code>)</p>
  <pre><code>$ pytest test.py -s
  platform linux -- Python 3.7.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
  rootdir: /Users/maikel/docker/library/postgresql
  collected 1 item
  
  test.py .
  
  =========================== 1 passed in 0.02s ===========================
  </code></pre>
  <p>❌ Runs unsuccessfully without <code>-s</code></p>
  <pre><code>$ pytest test.py
  ========================== test session starts ==========================
  platform linux -- Python 3.7.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
  rootdir: /Users/maikel/docker/library/postgresql
  collected 1 item
  
  test.py F                                                                                                                                                                                                                      [100%]
  
  ================================ FAILURES ===============================
  _____________________________ TestCase.test _____________________________
  
  self = &lt;test.TestCase testMethod=test&gt;
  
      def test(self):
          process = subprocess.run(
              [&quot;sh&quot;, &quot;./has-stdin.sh&quot;],
              stderr=subprocess.PIPE,
              stdout=subprocess.PIPE,
              check=True,
              shell=False
          )
  &gt;       assert process.stdout.decode(&quot;utf-8&quot;) == &quot;no\n&quot;
  E       AssertionError: assert 'yes\n' == 'no\n'
  E         - no
  E         + yes
  
  test.py:23: AssertionError
  ======================== short test summary info ========================
  FAILED test.py::TestCase::test - AssertionError: assert 'yes\n' == 'no\n'
  =========================== 1 failed in 0.10s ===========================
  
  </code></pre>
  <hr />
  <p> What is making the difference in using <code>-s</code>? How to run this pytest successfully without <code>-s</code>?</p>
  <p>I've tried <a href="https://stackoverflow.com/questions/61768797/test-calling-of-an-external-script-run-via-popen-that-expects-no-available-data">Test calling of an external script run via Popen that expects no available data in stdin using pytest</a>, but when using that method both <code>pytest</code> commands fail.</p>