opened
supunkamburugamuve
username_0
Should I run the python file? It would be nice to have this in the documentation.
How can I run the test files?
issue
created
MSeal
username_1
The simplest is to run pytest and follow it's documentation for running tests. But you can use python's built-in unittest, or nose, or any other test runner. I think it makes sense for us to link to [pytest's usage docs](https://docs.pytest.org/en/stable/usage.html) in our docs. Thanks for the call out
comment
created
moose-in-australia
username_2
Could you please provide an example of how to use any of these test runners? I'm really struggling to figure out how to use them together with testbook.
comment
created
MSeal
username_1
Sure you can copy a subset of the testbook tests as an example. Put the snippet below in your `tests/test_example.py` file along with an empty `tests/__init__.py, and copy https://github.com/nteract/testbook/blob/master/testbook/tests/resources/foo.ipynb into `tests/foo.ipynb`

```python
import pytest

from testbook import testbook

@pytest.fixture(scope='module')
def notebook():
    with testbook('tests/foo.ipynb', execute=True) as tb:
        yield tb

def test_execute_cell(notebook):
    notebook.execute_cell(1)
    assert notebook.cell_output_text(1) == 'hello world\n[1, 2, 3]'
```

To install and run pytest, testbook, (and to not pull the new ipykernel version we haven't patched against) do:

```bash
# This installs a virtual environment to isolate dependencies in the example... it's not needed if pip points to a python 3 package already
python3 -m venv .testenv
. .testenv/bin/activate
pip install pytest testbook "ipykernel<5.5"
# Here's your pytest command
pytest
```

You should see a single green test.

![single-test](https://user-images.githubusercontent.com/1863892/111585284-51066480-877c-11eb-8e6d-4433e570edce.png)
comment
created
moose-in-australia
username_2
Thank you so much! This works. :)
comment
created
MSeal
username_1
Great the hear! I think translating those instructions with some improvements into our reathedocs should be the task for whomever gets to resolving this ticket then
comment
created
willingc
username_3
Next action:

Following the steps described above create a tutorial page for the documentation.
comment