I've migrated Cumin from 'nose' to 'pytest' a while ago, here's a
summary of my experience.
First of all we need to distinguish the two main parts of Python
tests: writing the tests and collecting and running them.
In the classical setup, 'unittest' would be used for writing the tests
and 'nose' for collecting and running them, often wrapped in a call to
To use 'pytest' just as a test collector and runner, basically means
replacing 'nose' with 'pytest' and 'coverage' with the
module and adding 'pytest-runner' to the 'setup_requires' in setup.py.
There are some caveats though, depending how many nose-specific
features are used and if any unsupported idiom is used, see also 
Given the status of 'nose', I've looked at 'nose2', but it didn't
mature enough and actively developed. When I looked at it few months
ago that was no commit in the last 6-months and the latest release is
from mid-2016. I've seen that there has been some recent activity
I then chose 'pytest' as I got the impression that the Python
community is slowly moving towards it. In the process I've also got
some quick and friendly help on their issue tracker.
I've done this migration in Cumin primarily because I wanted to
overcome some limitations in the previous setup, namely:
- more compact output of passing tests, listing dots per file and not
naming them all
- more verbose output on failing tests with the stacktrace, the code
involved and an easy way to collect separately stderr and stdout
- coverage plugin works with multiprocess testing (very useful for
integration tests) while nose+coverage did not work (known limitation)
Once this step is done, the other, optional but somehow natural step,
is to use 'pytest' also for writing the tests, replacing 'unittest'.
This could be partly automated by a tool like , although in my
experience it doesn't cover all the cases and needs some manual
cleanup, but surely helps.
This allows to take full advantage of all the pytest features, as some
are not compatible with unittest-based tests.
I've done this migration for the integration tests of Cumin to take
advantage of 'pytest' parametrization feature  that was very useful
in my case for integration tests that were automatically generated.
Once that was done, I've decided to migrate everything to 'pytest' because:
- coherence, to not have integration tests written with 'pytest' and
unit test written with 'unittest'
- to be able in the future to use advanced features of pytest in the
unittests, because they will most likely not work in unittest.TestCase
subclasses (and indeed it happened)
- style-wise 'unittest' doesn't follow PEP8
The main style-related drawback of using 'pytest' for unit tests is
that all the 'self.assertSomeThing(foo)' must be replaced by standard
asserts like 'assert foo == something', and the assert lines don't go
nicely multiline because is not possible to use parentheses. But this
can be easily avoided just assigning the expected and test result
values to variables just before doing the assert.
If you have specific questions while migrating your project, feel free
to contact me  or add me as code reviewer on Gerrit (user: Volans).
On Wed, Nov 1, 2017 at 7:34 PM, Greg Grossmeier <greg(a)wikimedia.org> wrote:
(adding in qa@ list)
<quote name="Kunal Mehta" date="2017-11-01" time="11:15:42
-----BEGIN PGP SIGNED MESSAGE-----
On 11/01/2017 10:53 AM, Grace Gellerman wrote:
=== Scoring Platform === ** Converted our tests
from nosetests to
pytest (Anyone else making the transition?) *** nosetests is
under-maintained *** python community is moving towards pytest ***
converting our repos was pretty straightforward
I didn't realize nose was in such a state :( They put a notice on
their website, but I always skipped it.
pytest claims that it's compatible with nose out of the box - was
that the experience you had as well?
Off the top of my head, Pywikibot, CI, and other miscellaneous
projects all use nose and should probably be migrated over to pytest.
- -- Legoktm
-----BEGIN PGP SIGNATURE-----
-----END PGP SIGNATURE-----
Wikitech-l mailing list
| Greg Grossmeier GPG: B2FA 27B1 F7EB D327 6B8E |
| Release Team Manager A18D 1138 8E47 FAC8 1C7D |
Wikitech-l mailing list