Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inpossible to capture output when using https://testfixtures.readthedocs.io/en/latest/ package #339

Open
mgzenitech opened this issue Jul 1, 2022 · 0 comments

Comments

@mgzenitech
Copy link

Example:

from subprocess import check_call
from testfixtures import OutputCapture
from ward import test

@test("if correct command were called?")
def _() -> None:
    with OutputCapture(fd = True) as stdout:
        check_call([
            "echo",
            "ABC"
        ])
    stdout.compare("ABC\n")
──────────────────────────────────────────────────────────────────────────────── Ward 0.66.0b0 | CPython 3.9.9 ─────────────────────────────────────────────────────────────────────────────────
Loaded config from pyproject.toml.
Found 1 test and 0 fixtures in 0.02 seconds.

 FAIL  __test:5 if correct command were called?                                                                                                                                                 

                                                                                                                                                                                                
─────────────────────────────────────────────────────────────────────────────── if correct command were called? ────────────────────────────────────────────────────────────────────────────────
                                                                                                                                                                                                
  Failed at lib/python/utils/file_system/__test.py                                                                                                                                              
  ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮                                                                                          
  │ /home/mariusg/Documents/Projects/infra-terraform/lib/python/utils/file_system/__test.py:7 in _   │                                                                                          
  │                                                                                                  │                                                                                          
  │    4                                                                                             │                                                                                          
  │    5 @test("if correct command were called?")                                                    │                                                                                          
  │    6 def _() -> None:                                                                            │                                                                                          
  │ ❱  7 │   with OutputCapture(fd = True) as stdout:                                                │                                                                                          
  │    8 │   │   check_call([                                                                        │                                                                                          
  │    9 │   │   │   "echo",                                                                         │                                                                                          
  │   10 │   │   │   "ABC"                                                                           │                                                                                          
  │                                                                                                  │                                                                                          
  │ /home/mariusg/.pyenv/versions/3.9.9/lib/python3.9/site-packages/testfixtures/outputcapture.py:49 │                                                                                          
  │ in __enter__                                                                                     │                                                                                          
  │                                                                                                  │                                                                                          
  │    46 │   │   │   self.output = StringIO()                                                       │                                                                                          
  │    47 │   │   │   self.stdout = StringIO()                                                       │                                                                                          
  │    48 │   │   │   self.stderr = StringIO()                                                       │                                                                                          
  │ ❱  49 │   │   self.enable()                                                                      │                                                                                          
  │    50 │   │   return self                                                                        │                                                                                          
  │    51 │                                                                                          │                                                                                          
  │    52 │   def __exit__(self, *args):                                                             │                                                                                          
  │                                                                                                  │                                                                                          
  │ ╭────────────────────────────────── locals ──────────────────────────────────╮                   │                                                                                          
  │ │ self = <testfixtures.outputcapture.OutputCapture object at 0x7f1d39c349a0> │                   │                                                                                          
  │ ╰────────────────────────────────────────────────────────────────────────────╯                   │                                                                                          
  │                                                                                                  │                                                                                          
  │ /home/mariusg/.pyenv/versions/3.9.9/lib/python3.9/site-packages/testfixtures/outputcapture.py:73 │                                                                                          
  │ in enable                                                                                        │                                                                                          
  │                                                                                                  │                                                                                          
  │    70 │   │   "Enable the output capture if it is disabled."                                     │                                                                                          
  │    71 │   │   if self.original_stdout is None:                                                   │                                                                                          
  │    72 │   │   │   if self.fd:                                                                    │                                                                                          
  │ ❱  73 │   │   │   │   self.original_stdout = os.dup(sys.stdout.fileno())                         │                                                                                          
  │    74 │   │   │   │   self.original_stderr = os.dup(sys.stderr.fileno())                         │                                                                                          
  │    75 │   │   │   else:                                                                          │                                                                                          
  │    76 │   │   │   │   self.original_stdout = sys.stdout                                          │                                                                                          
  │                                                                                                  │                                                                                          
  │ ╭────────────────────────────────── locals ──────────────────────────────────╮                   │                                                                                          
  │ │ self = <testfixtures.outputcapture.OutputCapture object at 0x7f1d39c349a0> │                   │                                                                                          
  │ ╰────────────────────────────────────────────────────────────────────────────╯                   │                                                                                          
  ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                          
  UnsupportedOperation: fileno                                                                                                                                                                  
                                                                                                                                                                                                
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
╭──────────── Results ────────────╮
│  1  Test Encountered            │
│  1  Failures          (100.0%)  │
╰─────────────────────────────────╯
──────────────────────────────────────────────────────────────────────────────────── FAILED in 0.20 seconds ────────────────────────────────────────────────────────────────────────────────────

More info on simplistix/testfixtures#177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant