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

update Python testing section #220

Closed
egpbos opened this issue Jun 2, 2020 · 7 comments · Fixed by #260
Closed

update Python testing section #220

egpbos opened this issue Jun 2, 2020 · 7 comments · Fixed by #260

Comments

@egpbos
Copy link
Member

egpbos commented Jun 2, 2020

The Python testing section imho can be trimmed a bit and needs to be updated. The current section reads:

## Testing

* [pytest](https://docs.pytest.org/) is a full featured Python
testing tool. You can use it with `unittest`.
[Pytest intro](http://pythontesting.net/framework/pytest/pytest-introduction/)
* [Using mocks in Python](http://www.drdobbs.com/testing/using-mocks-in-python/240168251)
* [unittest](https://docs.python.org/3/library/unittest.html) is a
framework available in Python Standard Library.
[Dr.Dobb's on Unit Testing with Python](http://www.drdobbs.com/testing/unit-testing-with-python/240165163)
* [doctest](https://docs.python.org/3/library/doctest.html) searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown. Always use this if you have example code in your documentation to make sure your examples actually work.

Using `pytest` is preferred over `unittest`, `pytest` has a much more concise syntax and supports many useful features.

Please make sure the command `python setup.py test` can be used to run your tests. When using `pytest`, this can be easily configured as described in the [`pytest` documentation](https://docs.pytest.org/en/latest/goodpractices.html#integrating-with-setuptools-python-setup-py-test-pytest-runner).

I would suggest removing unittest altogether, since we recommend pytest. We don't need to list all alternatives.

The bottom paragraph should be removed altogether, since the test command in setuptools has been deprecated: pypa/setuptools#1878 pytest-dev/pytest#5534

Any objections, additions or other thoughts? If not, I'll make a PR or if someone else wants to do it, by all means :)

@egpbos
Copy link
Member Author

egpbos commented Jun 2, 2020

The second to last paragraph can also be removed if we remove unittest from the list.

@bouweandela
Copy link
Member

I mostly agree, though as far as I know there is no substitute for unittest.mock in pytest. You can use that nicely with pytest through the mocker fixture provided by the pytest-mock plugin though.

@LourensVeen
Copy link
Member

I didn't know about pytest-mock, but I've been using MagicMock and patch for years with pytest, works fine.

Maybe a note should be added that there are many useful pytest plug-ins in general? I use several for linting, like pytest-pycodestyle and pytest-mypy, and it's quite convenient. If you're new to pytest, that may be nice to know.

@bouweandela
Copy link
Member

pytest-flake8, pytest-cov, pytest-html and pytest-xdist (or pytest-parallel) might also be nice to mention.

@bouweandela
Copy link
Member

More plugin info: https://docs.pytest.org/en/stable/plugins.html

@LourensVeen
Copy link
Member

Ah yes, I can recommend pytest-cov and pytest-xdist. The latter was useful in Cerise, where I had to build Docker images as part of the tests, and with xdist that could be done in parallel, which sped things up a lot.

egpbos added a commit to egpbos/guide that referenced this issue Jun 4, 2020
@egpbos
Copy link
Member Author

egpbos commented Jun 4, 2020

Ok, great comments, I tried to sum it all up in an updated section, please check it out in #219. Accidentally pushed it to that PR branch, which in the end I think is fine, because it was only a link fix and wasn't merged yet anyway.

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

Successfully merging a pull request may close this issue.

3 participants