LoginSignup
2
2

More than 5 years have passed since last update.

unittest.TestCase を継承した class 内の yield は nose では動いてくれなかった (nose のバージョンによって?)

Last updated at Posted at 2015-07-10

実験

test_sample.py
# coding: utf-8
from unittest import TestCase
from nose.tools import eq_


class SampleTest(TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_sample(self):
        """
        テストサンプル
        """
        for i in xrange(3):
            yield eq_, True, False

しても、

$ nosetests -s -v test_sample.py
テストサンプル ... ok

----------------------------------------------------------------------
Ran 1 tests in 0.001s

みたいになって期待通りには動いてくれなかった。

下記のように修正、

test_sample.py
# coding: utf-8
from nose.tools import eq_


def test_sample():
    """
    テストサンプル
    """
    for i in xrange(3):
        yield eq_, True, False

すると、

$ nosetests -s -v test_sample.py
テストサンプル ... FAIL
テストサンプル ... FAIL
テストサンプル ... FAIL

======================================================================
FAIL: テストサンプル
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/Cellar/numpy/1.9.2/libexec/nose/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
AssertionError: True != False

======================================================================
FAIL: テストサンプル
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/Cellar/numpy/1.9.2/libexec/nose/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
AssertionError: True != False

======================================================================
FAIL: テストサンプル
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/Cellar/numpy/1.9.2/libexec/nose/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
AssertionError: True != False

----------------------------------------------------------------------
Ran 3 tests in 0.011s

FAILED (failures=3)

みたいにちゃんと期待通りに動いた。

nose さん、さようなら。 pytest さんのところに行こうと思います…。
artigatougozaimashita.

資料

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2