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

attempt to replace nose with pytest #2217

Merged
merged 10 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

The bottom line. Follow your Nose, or our Nose. Write-run-love tests :fist:.
Thank you for contributing to plotly.py!

## Code of Conduct

Expand Down Expand Up @@ -128,34 +128,34 @@ classes based on the new schema.
We take advantage of two tools to run tests:

* [`tox`](https://tox.readthedocs.io/en/latest/), which is both a virtualenv management and test tool.
* [`nose`](https://nose.readthedocs.org/en/latest/), which is is an extension of Python's unittest
* [`pytest`](https://docs.pytest.org/en/latest/), a powerful framework for unit testing.

### Running Tests with `nose`
### Running Tests with `pytest`

Since our tests cover *all* the functionality, to prevent tons of errors from showing up and having to parse through a messy output, you'll need to install `optional-requirements.txt` as explained above.

After you've done that, go ahead and follow (y)our Nose!
After you've done that, go ahead and run the test suite!

```bash
nosetests -w packages/python/plotly/plotly/tests/
pytest packages/python/plotly/plotly/tests/
```

Or for more *verbose* output:

```bash
nosetests -w packages/python/plotly/plotly/tests/ -v
pytest -v packages/python/plotly/plotly/tests/
```

Either of those will run *every* test we've written for the Python API. You can get more granular by running something like:

```bash
nosetests -w packages/python/plotly/plotly/tests/test_core/
pytest packages/python/plotly/plotly/tests/test_core/
```

... or even more granular by running something like:

```bash
nosetests plotly/tests/test_plotly/test_plot.py
pytest plotly/tests/test_plotly/test_plot.py
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh can we add here the incantation for running a single test? I think it’s with a colon? I always forget it!


### Running tests with `tox`
Expand Down Expand Up @@ -187,16 +187,16 @@ Where `TOXENV` is the environment list you want to use when invoking `tox` from
* `tox` will automatically manage a virtual env for each environment you want to test in.
* You only have to run `tox` and know that the module is working in both `Python 2` and `Python 3`.

Finally, `tox` allows you to pass in additional command line arguments that are formatted in (by us) in the `tox.ini` file, see `{posargs}`. This is setup to help with our `nose attr` configuration. To run only tests that are *not* tagged with `slow`, you could use the following command:
Finally, `tox` allows you to pass in additional command line arguments that are formatted in (by us) in the `tox.ini` file, see `{posargs}`. This is setup to help with our configuration of [pytest markers](http://doc.pytest.org/en/latest/example/markers.html), which are set up in `packages/python/plotly/pytest.ini`. To run only tests that are *not* tagged with `nodev`, you could use the following command:

```bash
tox -- -a '!slow'
tox -- -a '!nodev'
```

Note that anything after `--` is substituted in for `{posargs}` in the tox.ini. For completeness, because it's reasonably confusing, if you want to force a match for *multiple* `nose attr` tags, you comma-separate the tags like so:
Note that anything after `--` is substituted in for `{posargs}` in the tox.ini. For completeness, because it's reasonably confusing, if you want to force a match for *multiple* `pytest` marker tags, you comma-separate the tags like so:

```bash
tox -- -a '!slow','!matplotlib'
tox -- -a '!nodev','!matplotlib'
```

### Writing Tests
Expand Down
13 changes: 6 additions & 7 deletions packages/python/chart-studio/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
; PASSING ADDITONAL ARGUMENTS TO TEST COMMANDS
; The {posargs} is tox-specific and passes in any command line args after `--`.
; For example, given the testing command in *this* file:
; nosetests {posargs} -x plotly/tests/test_core
; pytest {posargs} -x plotly/tests/test_core
;
; The following command:
; tox -- -a '!slow'
; tox -- -k 'not nodev'
;
; Tells tox to call:
; nosetests -a '!slow' -x plotly/tests/test_core
; pytest -k 'not nodev' -x plotly/tests/test_core
;
; Which is a nice way to skip slow tests for faster testing cycles.

[tox]
; The py{A,B,C}-{X,Y} generates a matrix of envs:
Expand Down Expand Up @@ -72,16 +71,16 @@ deps=
basepython={env:PLOTLY_TOX_PYTHON_27:}
commands=
python --version
nosetests {posargs} -x chart_studio/tests/
pytest {posargs} -x chart_studio/tests/

[testenv:py35-plot_ly]
basepython={env:PLOTLY_TOX_PYTHON_35:}
commands=
python --version
nosetests {posargs} -x chart_studio/tests/
pytest {posargs} -x chart_studio/tests/

[testenv:py37-plot_ly]
basepython={env:PLOTLY_TOX_PYTHON_37:}
commands=
python --version
nosetests {posargs} -x chart_studio/tests/
pytest {posargs} -x chart_studio/tests/
1 change: 0 additions & 1 deletion packages/python/plotly/optional-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ numpy
## testing dependencies ##
coverage==4.3.1
mock==2.0.0
nose==1.3.3
pytest==3.5.1
backports.tempfile==1.0
xarray
Expand Down
7 changes: 3 additions & 4 deletions packages/python/plotly/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
; PASSING ADDITONAL ARGUMENTS TO TEST COMMANDS
; The {posargs} is tox-specific and passes in any command line args after `--`.
; For example, given the testing command in *this* file:
; nosetests {posargs} -x plotly/tests/test_core
; pytest {posargs} -x plotly/tests/test_core
;
; The following command:
; tox -- -a '!slow'
; tox -- -k 'not nodev'
;
; Tells tox to call:
; nosetests -a '!slow' -x plotly/tests/test_core
; pytest -k 'not nodev' -x plotly/tests/test_core
;
; Which is a nice way to skip slow tests for faster testing cycles.

[tox]
; The py{A,B,C}-{X,Y} generates a matrix of envs:
Expand Down