ModuleNotFoundError: No module named ‘numpy.testing.nosetester’

This is happening due to a version incompatibility between numpy and scipy. numpy in its latest versions have deprecated numpy.testing.nosetester. Replicating the issue pip install numpy==1.18 # > 1.18 pip install scipy<=0.19.0 # <= 0.19 and from sklearn.tree import DecisionTreeClassifier as DTC Triggers the error. Fixing the error Upgrade your scipy to a higher version. … Read more

Nose unable to find tests in ubuntu

The other thing which always gets me with nose is that it won’t run tests in executable files. I’m not exactly sure why that would make a difference across Mac/Ubuntu, but it’s worth a shot. Make sure that the scripts didn’t somehow get chmod +x‘d on the Mac… And if they did, fix them with … Read more

Why python mock patch doesn’t work?

Access bar using spike.bar. Imported bar is not affected by mock.patch. from unittest import TestCase import unittest from mock import patch, MagicMock from spike import T1 import spike # <—- class TestShit(TestCase): @patch(‘spike.T1.foo’, MagicMock(return_value=”patched”)) def test_foo(self): foo = T1().get_foo() self.assertEqual(‘patched’, foo) @patch(‘spike.bar’) def test_bar(self, mock_obj): mock_obj.return_value=”patched” bar = spike.bar() # <—– self.assertEqual(‘patched’, bar) if __name__ … Read more

Getting Python’s unittest results in a tearDown() method

As of March 2022 this answer is updated to support Python versions between 3.4 and 3.11 (including the newest development Python version). Classification of errors / failures is the same that is used in the output unittest. It works without any modification of code before tearDown(). It correctly recognizes decorators skipIf() and expectedFailure. It is … Read more