Repository: cocotb/cocotb

Issue:
ipython_support and pytest assertion rewriting don't work together
When running `make MODULE=cocotb.ipython_support` while in any of the examples or tests I get the following error.

```
     0.00ns ERROR    cocotb.regression                         regression.py:408  in _score_test                     Test Failed: run_ipython (result was OSError)
                                                                                                                     Traceback (most recent call last):
                                                                                                                       File "/home/kaleb/dev/cocotb/cocotb/ipython_support.py", line 88, in run_ipython
                                                                                                                         await embed(user_ns=dict(dut=dut))
                                                                                                                       File "/home/kaleb/dev/cocotb/cocotb/ipython_support.py", line 77, in embed
                                                                                                                         await run_shell()
                                                                                                                       File "/home/kaleb/dev/cocotb/cocotb/scheduler.py", line 671, in wrapper
                                                                                                                         return waiter.result  # raises if there was an exception
                                                                                                                       File "/home/kaleb/dev/cocotb/cocotb/scheduler.py", line 104, in result
                                                                                                                         return self._outcome.get()
                                                                                                                       File "/home/kaleb/dev/cocotb/cocotb/outcomes.py", line 53, in get
                                                                                                                         raise self.error
                                                                                                                       File "/home/kaleb/dev/cocotb/cocotb/ipython_support.py", line 76, in run_shell
                                                                                                                         shell()
                                                                                                                       File "/home/kaleb/miniconda3/lib/python3.8/site-packages/IPython/terminal/embed.py", line 228, in __call__
                                                                                                                         self.mainloop(local_ns, module, stack_depth=stack_depth,
                                                                                                                       File "/home/kaleb/miniconda3/lib/python3.8/site-packages/IPython/terminal/embed.py", line 324, in mainloop
                                                                                                                         self.interact()
                                                                                                                       File "/home/kaleb/miniconda3/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 547, in interact
                                                                                                                         code = self.prompt_for_code()
                                                                                                                       File "/home/kaleb/miniconda3/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 290, in prompt
                                                                                                                         lines = [input(prompt_text)]
                                                                                                                       File "/home/kaleb/miniconda3/lib/python3.8/site-packages/IPython/utils/py3compat.py", line 147, in input
                                                                                                                         return builtin_mod.input(prompt)
                                                                                                                       File "/home/kaleb/miniconda3/lib/python3.8/site-packages/_pytest/capture.py", line 217, in read
                                                                                                                         raise OSError(
                                                                                                                     OSError: pytest: reading from stdin while output is captured!  Consider using `-s`.
```

After commenting out the following section I drop into an ipython shell successfully.

https://github.com/cocotb/cocotb/blob/98f9184a5acce44e5c0ebcf40222a15be524b7dd/cocotb/__init__.py#L290-L305



Discussion:
I don't really understand why output capturing is being enabled here. What version of pytest are you using, and does the assertion rewriting still work properly for you in non-ipython cases?
~I'm not seeing the error in WSL2, but I'm not using conda.~
Edit: I didn't have `pytest` installed 😆 

Taking the hint from the error, we could use
```py3
pytest_conf = Config.fromdictargs({}, ['--capture=no'])
```
to ensure there is no capture. (This fixes it for me)

Resolving patch:
diff --git a/cocotb/__init__.py b/cocotb/__init__.py
--- a/cocotb/__init__.py
+++ b/cocotb/__init__.py
@@ -297,7 +297,7 @@ def _initialise_testbench_(argv_):
             # import the test modules.
             from _pytest.config import Config
             from _pytest.assertion import install_importhook
-            pytest_conf = Config.fromdictargs([], {})
+            pytest_conf = Config.fromdictargs({}, ['--capture=no'])
             install_importhook(pytest_conf)
         except Exception:
             log.exception(


Test patch:
diff --git a/tests/test_cases/test_cocotb/test_pytest.py b/tests/test_cases/test_cocotb/test_pytest.py
--- a/tests/test_cases/test_cocotb/test_pytest.py
+++ b/tests/test_cases/test_cocotb/test_pytest.py
@@ -4,6 +4,7 @@
 """ Tests relating to pytest integration """
 
 import cocotb
+from cocotb.result import TestFailure
 
 # pytest is an optional dependency
 try:
@@ -16,7 +17,9 @@
 async def test_assertion_rewriting(dut):
     """ Test that assertion rewriting hooks take effect in cocotb tests """
     try:
-        assert 1 != 42
+        assert 1 == 42
     except AssertionError as e:
         assert "42" in str(e), (
             f"Assertion rewriting seems not to work, message was {e}")
+    else:
+        raise TestFailure('AssertionError was not thrown')