nose

Skip a unit test from a Nose2 Plugin

Skip a unit test from a Nose2 Plugin Question: I’m having trouble actually skipping a unit test from a Nose2 plugin. I am able to mark the test skipped and see the reason in the final result, but the test still runs. This example code should basically skip any test, as long as the plugin …

Total answers: 2

nose vs pytest – what are the (subjective) differences that should make me pick either?

nose vs pytest – what are the (subjective) differences that should make me pick either? Question: I’ve started working on a rather big (multithreaded) Python project, with loads of (unit)tests. The most important problem there is that running the application requires a preset environment, which is implemented by a context manager. So far we made …

Total answers: 1

How to make nosetests use python3

How to make nosetests use python3 Question: I try to use nosetests ❯ nosetests ‘/pathTo/test’ but it uses python 2.7 for my tests: sys.version_info(major=2, minor=7, micro=5, releaselevel=’final’, serial=0) So some of them fails, because they were written in python 3.3. I work it around and installed virtual environment: pyvenv-3.3 py3env Activated it: source ~/py3env/bin/activate Check …

Total answers: 4

Why python mock patch doesn't work?

Why python mock patch doesn't work? Question: I have two files spike.py class T1(object): def foo(self, afd): return “foo” def get_foo(self): return self.foo(1) def bar(): return “bar” test_spike.py: from unittest import TestCase import unittest from mock import patch, MagicMock from spike import T1, bar class TestStuff(TestCase): @patch(‘spike.T1.foo’, MagicMock(return_value=’patched’)) def test_foo(self): foo = T1().get_foo() self.assertEqual(‘patched’, foo) …

Total answers: 3

Python – How to unmock/reset mock during testing?

Python – How to unmock/reset mock during testing? Question: I’m using nosetests and in two separate files I have two tests. Both run fine when run individually, but when run together, the mock from the first test messes up the results in the second test. How do I insure that all mocks/patches are reset after …

Total answers: 1

Mocking two functions with patch for a unit test

Mocking two functions with patch for a unit test Question: I have a function I want to unit test contains calls two other functions. I am unsure how can I mock both functions at the same time properly using patch. I have provided an example of what I mean below. When I run nosetests, the …

Total answers: 4

How to set self.maxDiff in nose to get full diff output?

How to set self.maxDiff in nose to get full diff output? Question: When using nose 1.2.1 with Python 3.3.0, I sometimes get an error message similar to the following one ====================================================================== FAIL: maxdiff2.test_equal ———————————————————————- Traceback (most recent call last): File “/usr/local/lib/python3.3/site-packages/nose/case.py”, line 198, in runTest self.test(*self.arg) File “/Users/loic/cmrsj/Calculus_II/scrap/maxdiff2.py”, line 32, in test_equal assert_equal(str1, str2) AssertionError: …

Total answers: 7

How to Fix Python Nose: Coverage not available: unable to import coverage module

How to Fix Python Nose: Coverage not available: unable to import coverage module Question: I can’t seem to get code coverage with Nose to work, despite having the plugin installed. Any ideas on how to fix this? 12:15:25 ~/sandbox/ec$ nosetests –plugins Plugin xunit Plugin deprecated Plugin skip Plugin multiprocess Plugin failuredetail Plugin capture Plugin logcapture …

Total answers: 2

How to exclude mock package from python coverage report using nosetests

How to exclude mock package from python coverage report using nosetests Question: I currently try to use the mock library to write some basic nose unittests in python. After finishing some basic example I now tried to use nosetests –with-coverage and now I have the mock package and the package I tried to ‘mock away’ …

Total answers: 3