Migrate tests to pytest
away from unittest
#986
Labels
code health
readability, maintainability, best practices, etc
refactor
Substantial projects to make the code do the same thing, better.
tests
integration & unit testing, bug triage and prevention
Context
In our delphi-epidata tests we’ve been using a mix of
pytest
andunittest
. This has mostly worked seamlessly, because most of the features we use from unittest, like setUp and tearDown methods andunittest.skip
are supported bypytest
. I want to make a case for moving away from usingunittest
:pytest.mark.parametrize
to parametrize a method from a test class that subclasses fromunittest.TestCase
(I got errors I wasn’t able to untangle)parametrize
: you have a test that takes a CSV file as input and checks that it's processed correctly; the test can be kept the same, parametrized over multiple CSV files, and pytest will naturally separate any failing CSV files into their own test (no need to hunt in a for-loop for the failing CSV)I got a yes from @melange396 and a yes from @krivard (minus preferring
unittest
's typed assert statements [see migration below]; maybe we can see how to mitigate this).Migration
Migrating over to pure
pytest
has a simple part and a hard part:setUp
tosetup_method
andtearDown
toteardown_method
and@unittest.skip
to@pytest.mark.skip
unittest.assertEqual
type checks to regularassert
statements. Thepytest
philosophy is to always useassert
and report error context depending on the types and the operand. Searching forself.assert
in thedelphi-epidata
codebase yields 1582 results, so this would take a bit of timeHelp
I'll do the easy part in a PR soon. For the hard part, any and all help is welcome! Feel free to add partial PRs and link them to this issue! Also feel free to edit this post to organize the work, so we know which parts of the codebase still need to be migrated.
The text was updated successfully, but these errors were encountered: