Open tremble opened 2 years ago
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.
@samccann is this issue available to be contributed to? Would love to work on it
@Aysha-py best option is to start the work and open a draft Pull Request. If you add fixes: ansible/ansible-documentation#81
to the PR description it will automatically link to this issue (and close the issue when the PR is merged). That link will show up and means folks know you're working on it.
@tremble okay, can you give further clarification on updating these docs? Do I update the unittest docs to pytest? If so where can I access the content of pytest?
The current docs are linked in the original issue description. You'll find some examples doing things like
class TestMyModule(unittest.TestCase):
def setUp(self):
...
unittest.TestCase
isn't needed as the superclass (pytest doesn't require it), however setUp
needs to be replaced with setup_method
There's some more information in the pytest docs: https://docs.pytest.org/en/latest/how-to/xunit_setup.html#method-and-function-level-setup-teardown
I also found https://www.jitsejan.com/moving-from-unittest-to-pytest which looks like it explains some of what's going on.
pytest doesn't require it
Moreover: it is harmful even to inherit from unittest.TestCase
under the pytest runner because it prevents usage of many pytest features — https://docs.pytest.org/en/latest/how-to/unittest.html#pytest-features-in-unittest-testcase-subclasses.
Besides, with pytest fixtures, using classes is not really necessary — it's much cleaner to have setup and teardown in fixtures. And there's no need for an extra namespace for the test callables (a test module is already one).
Summary
Speaking to @mattclay, using the
pytest
framework for unit tests is preferred overunittest
framework.Both https://github.com/ansible/ansible/blob/devel/docs/docsite/rst/dev_guide/testing_units.rst and https://github.com/ansible/ansible/blob/devel/docs/docsite/rst/dev_guide/testing_units_modules.rst have a mix of both frameworks in the examples, the
unittest
examples should probably be migrated over to usingpytest
.Issue Type
Documentation Report
Component Name
docs/docsite/rst/dev_guide/testing_units.rst
Ansible Version
Configuration
OS / Environment
n/a
Additional Information
If we want folks to prefer pytest over unittest, we need to update the docs to reflect this.
Code of Conduct