code: def test_get_stderr_fileno_invalid_fd() -> None:
      """Test for faulthandler being able to handle invalid file descriptors for stderr (#8249)."""
      from _pytest.faulthandler import get_stderr_fileno
  
      class StdErrWrapper(io.StringIO):
          """
          Mimic ``twisted.logger.LoggingFile`` to simulate returning an invalid file descriptor.
  
          https://github.com/twisted/twisted/blob/twisted-20.3.0/src/twisted/logger/_io.py#L132-L139
          """
  
          def fileno(self):
              return -1
  
      wrapper = StdErrWrapper()
  
      with pytest.MonkeyPatch.context() as mp:
          mp.setattr("sys.stderr", wrapper)
  
          # Even when the stderr wrapper signals an invalid file descriptor,
          # ``_get_stderr_fileno()`` should return the real one.
          assert get_stderr_fileno() == 2
  
file_path: pytest/testing/test_faulthandler.py
imports: import io
  import sys
  import pytest
  from _pytest.pytester import Pytester
label_desc: Use image node_id 9 for calling a global function with example usage: test_get_stderr_fileno_invalid_fd() and returns: unknown