Closed Joe-Heffer-Shef closed 5 months ago
I use pytest
but only because its the framework used when I learnt about writing tests. I've never used unittest
to be able to give a comparison.
Features I like about pytest
...
@pytest.mark.parametrize()
fixture where you define various inputs and expected outputs which are passed into the test. I'd be curious to find out more about unittest
but having learnt and being familiar with pytest
would be reluctant to switch (acquired knowledge and learning curve both being barriers to doing so).
My understanding is that a "test suite" is simply an existing set of tests for a given set of code.
Not sure about "test runner" the pytest-runner
extension/plugin is deprecated but appears to be a package that runs pytest
automatically on a package. No idea of its meaning in other frameworks.
Pytest Plugins for Flask testing...
I've never used Flask so can't comment on how useful they are for testing but still love using pytest
for my test development and use various plugins (of which there are lots) such as pytest-regtest (although they've an issue concerning dependency on py
which I suggested a solution for over a year ago but hasn't been accepted or closed), pytest-mpl and pytest-github-actions-annotate-failures.
Conditional coverage if you only want to calculate these statistics under certain conditions.
Just in time...
Pytest Parameterisation by Neil https://blog.nshephard.dev/posts/pytest-param/
Parallel test execution with pytest-xdist
https://pytest-xdist.readthedocs.io/
Lots of useful Pytest extensions including...
Additional ways of testing.
https://docs.python.org/3/library/unittest.html#class-and-module-fixtures
Regression test plugin https://gitlab.com/uweschmitt/pytest-regtest
https://github.com/CITCOM-project/CausalTestingFramework
"Regression testing is a common technique to implement basic testing before refactoring legacy code that lacks a test suite."
https://hypothesis.readthedocs.io/en/latest/ https://docs.python.org/3/library/doctest.html
Covered
My question: what are the advantages of using pytest rather than the inbuilt unittest library?
Does it help implement testing best practices and methodologies?
Why would I install
pytest
whenunittest
is built in to the core libraries?What can I do with
pytest
that I can't do with other libraries?Pytest claims:
unittest
claims:What do these concepts mean?