Yield in a class that inherits unittest.TestCase didn't work with nose (depending on the version of nose?)

Experiment

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):
        """
Test sample
        """
        for i in xrange(3):
            yield eq_, True, False

Even so

$ nosetests -s -v test_sample.py
Test sample... ok

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

It didn't work as expected.

Corrected as below,

test_sample.py


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


def test_sample():
    """
Test sample
    """
    for i in xrange(3):
        yield eq_, True, False

Then

$ nosetests -s -v test_sample.py
Test sample... FAIL
Test sample... FAIL
Test sample... FAIL

======================================================================
FAIL:Test sample
----------------------------------------------------------------------
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:Test sample
----------------------------------------------------------------------
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:Test sample
----------------------------------------------------------------------
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)

It worked as expected.

Goodbye, nose. I'm going to go to pytest ... artigatougozaimashita.

Document

Recommended Posts

Yield in a class that inherits unittest.TestCase didn't work with nose (depending on the version of nose?)
A story that didn't work when I tried to log in with the Python requests module
Feel free to write a test with nose (in the case of + gevent)
Difference in results depending on the argument of multiprocess.Process
A server that returns the number of people in front of the camera with bottle.py and OpenCV
Create a bot that only returns the result of morphological analysis with MeCab on Discord
A note on the default behavior of collate_fn in PyTorch
The story of creating a bot that displays active members in a specific channel of slack with python
A memo that reproduces the slide show (gadget) of Windows 7 on Windows 10.
Process the contents of the file in order with a shell script
A function that measures the processing time of a method in python
Find the rank of a matrix in the XOR world (rank of a matrix on F2)
The story of making a module that skips mail with python
Get the number of readers of a treatise on Mendeley in Python
A story that visualizes the present of Qiita with Qiita API + Elasticsearch + Kibana
Get a distributed representation of words in Fast with fastText on Facebook
Generate a list packed with the number of days in the current month.
Hit a method of a class instance with the Python Bottle Web API
Receive a list of the results of parallel processing in Python with starmap
Display the status of COVID 19 infection in Japan with Splunk (GitHub version)
I made a mistake in fetching the hierarchy with MultiIndex of pandas
A class that hits the DMM API
A collection of Numpy, Pandas Tips that are often used in the field
A solution to the problem that the Python version in Conda cannot be changed
[Linux] Difference in time information depending on the clock ID of the clock_gettime () function
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
If branch depending on whether there is a specific element in the list
To output a value even in the middle of a cell with Jupyter Notebook
In Python, change the behavior of the method depending on how it is called
The story of making a web application that records extensive reading with Django
Separately install a version of Python that is not pre-installed on your Mac
I didn't have to write a decorator in the class Thank you contextmanager
How to get a list of files in the same directory with python