Arrow: Transition testing framework from nose/chai to pytest

Created on 26 May 2019  路  9Comments  路  Source: arrow-py/arrow

nose and chai are not regularly updated anymore, so a transition to nose2 or pytest would be wise to explore.

For now, nose and chai seem to play fine with Python 2.7 through Python 3.8, but that could easily change in the future.

enhancement tests

Most helpful comment

I have started to work on this transition and I ultimately decided on replacing Chai with Python Mock and nose with pytest.

We will see dependencies shift from nose, nose-cov, and chai to pytest, pytest-cov, and pytest-mock.

All 9 comments

It is worth noting that nose emits a couple of deprecation warnings in Python 3.7 that may become bigger issues once Python 3.8 is released.

Yup just seen these warnings as well.

(arrow-37) chris@ThinkPad:~/arrow$ python -Wd -m nose
/home/chris/arrow-37/lib/python3.7/site-packages/nose/importer.py:12: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  from imp import find_module, load_module, acquire_lock, release_lock
/home/chris/arrow-37/lib/python3.7/site-packages/nose/suite.py:541: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  if isinstance(tests, collections.Callable) or isinstance(tests, unittest.TestSuite):

I'll look around to see if there's anyway to automatically convert nose/chai to another test suite.

edit: seems like these dprecations have been pushed back to 3.10 (see https://www.python.org/dev/peps/pep-0594/#deprecation-schedule)

I have started to work on this transition and I ultimately decided on replacing Chai with Python Mock and nose with pytest.

We will see dependencies shift from nose, nose-cov, and chai to pytest, pytest-cov, and pytest-mock.

@jadchaar - Need help with this transition? Was looking at this today when reviewing the requirements.txt for security vulnerabilities.

Besides pytest supporting most of nose out of the box, https://github.com/pytest-dev/nose2pytest might be of help.

Hey @andrewelkins great to hear from you! Glad to see you back!

My feature branch is actually quite stale at this point since there have been tons of updates (including the big 0.15.0 release) after I began the transition.

I did most of it manually (pretty tedious), but I got stuck on trying to mock the LRU cache functionality using pytest-mock and kind of gave up for a while. I tried to reach out the pytest for some help since I could not find any relevant resources on it and my implementation wasn't working, but I never got a response. If you have more experience with mocking, I'd love some help there.

I will definitely look into using nose2pytest when I try to attempt this again in the future.

I'll take a crack at the migration. Would be great to replace nose since it's essentially dead.

I agree, pytest is definitely the way to go since fixtures will make standardizing tests a breeze.

I used pytest, pytest-cov, and pytest-mock to get my transition branch started. I reached a deadend trying to mock the LRU cache behavior though. If you can figure out how to do that, the rest is straight forward: need to convert setup() to fixtures, replace any uses of Chai with pytest-mock, change unittest syntax to vanilla assert calls.

FWIW, the deprecations became error in Python 3.9 itself with https://github.com/python/cpython/pull/10596

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pganssle picture pganssle  路  5Comments

adm271828 picture adm271828  路  7Comments

liosha picture liosha  路  7Comments

mtrahan picture mtrahan  路  7Comments

andrewmwilson picture andrewmwilson  路  5Comments