# Doctest within ParaVIEW

**URL:** https://discourse.paraview.org/t/doctest-within-paraview/12975
**Category:** ParaView Support
**Tags:** python
**Created:** [October 3, 2023, 9:49am UTC](https://discourse.paraview.org/t/doctest-within-paraview/12975 "2023-10-03T09:49:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![atismer](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/da6949/32.png) [@atismer](https://discourse.paraview.org/u/atismer)
#### Post date: [October 3, 2023, 9:49am UTC](https://discourse.paraview.org/t/doctest-within-paraview/12975/1 "2023-10-03T09:49:53Z")

</div>

Dear Community,

I would like to run Doctests within Python. I created a simple testClass to describe my problem:

```python
class testClass:
  """
  >>> import sys
  >>> render = "paraview.simple" in sys.modules
  >>> if render:
  ... print("ParaVIEW available.")
 
  """
  def __init__ ( self ) -> None:
    pass
  
def testAndShow():
  import testClass
  import doctest
  doctest.testmod(
    m=testClass,
    name= __name__ , 
    verbose=True
  )

```

Then I would like to run ParaVIEW and execute the following within the Python shell:

```auto
>>> from paraview.simple import *
>>> from testClass import *
>>> testAndShow()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/ati/tmp/dtOO-application/pythonOO/testClass.py", line 26, in testAndShow
    verbose=True
  File "/usr/lib64/python3.6/doctest.py", line 1951, in testmod
    runner.run(test)
  File "/usr/lib64/python3.6/doctest.py", line 1445, in run
    encoding = save_stdout.encoding
AttributeError: 'vtkPythonStdStreamCaptureHelper' object has no attribute 'encoding'

```

So, what’S my mistake?

Thank you for your support.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [October 3, 2023, 10:42am UTC](https://discourse.paraview.org/t/doctest-within-paraview/12975/2 "2023-10-03T10:42:03Z")

</div>

It looks like our stream shim isn’t as transparent as it should be. Cc: @dgobbi

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dgobbi/32/11302_2.png) [@dgobbi](https://discourse.paraview.org/u/dgobbi)
#### Post date: [October 3, 2023, 12:51pm UTC](https://discourse.paraview.org/t/doctest-within-paraview/12975/3 "2023-10-03T12:51:28Z")

</div>

Python documents it [here](https://docs.python.org/3/library/io.html#id1). It looks like we should also add `.errors` and `.closed` in addition to `.encoding`.

---

<div class="post-metadata">

### Author: ![atismer](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/da6949/32.png) [@atismer](https://discourse.paraview.org/u/atismer)
#### Post date: [October 25, 2023, 12:32pm UTC](https://discourse.paraview.org/t/doctest-within-paraview/12975/4 "2023-10-25T12:32:04Z")

</div>

Does it mean that the stream shim will be extended to support the doctests within the paraview python shell?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [October 25, 2023, 7:11pm UTC](https://discourse.paraview.org/t/doctest-within-paraview/12975/5 "2023-10-25T19:11:17Z")

</div>

We _should_ (and likely will eventually). We should really open an issue to track it. I’ve done that here: [https://gitlab.kitware.com/vtk/vtk/-/issues/19145](https://gitlab.kitware.com/vtk/vtk/-/issues/19145)
