nose-devs / nose

nose is nicer testing for python
http://readthedocs.org/docs/nose/en/latest/
1.36k stars 397 forks source link

--failed option runs the passed tests as well. #1094

Open PabitraPati opened 4 years ago

PabitraPati commented 4 years ago
U:\>nosetests -V
nosetests version 1.3.7

U:\>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

I have a simple python test to check whether or not a number is even in test_even.py.

from nose.tools import assert_equal
def test_even1():
    assert_equal(1%2, 0)

def test_even2():
    assert_equal(2%2, 0)

def test_even3():
    assert_equal(3%2, 0)

def test_even4():
    assert_equal(4%2, 0)

I ran the above tests. ( expected 2 failures for test_even1 and test_even3).

C:\Python3\NOSE_Tests>nosetests test_even.py  -v
test_even.test_even1 ... FAIL
test_even.test_even2 ... ok
test_even.test_even3 ... FAIL
test_even.test_even4 ... ok

======================================================================
FAIL: test_even.test_even1
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\python3\lib\site-packages\nose\case.py", line 198, in runTest
    self.test(*self.arg)
  File "C:\Python3\NOSE_Tests\test_even.py", line 27, in test_even1
    assert_equal((1*1)%2, 0)
AssertionError: 1 != 0

======================================================================
FAIL: test_even.test_even3
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\python3\lib\site-packages\nose\case.py", line 198, in runTest
    self.test(*self.arg)
  File "C:\Python3\NOSE_Tests\test_even.py", line 34, in test_even3
    assert_equal((3*1)%2, 0)
AssertionError: 1 != 0

----------------------------------------------------------------------
Ran 4 tests in 0.009s

FAILED (failures=2)

Now I modified the failure tests test_even1 and test_even3 as follows :-

    assert_equal((1*2)%2, 0)

def test_even3():
    assert_equal((3*2)%2, 0)

Re-ran the failed tests only using --failed option. However, --failed is supposed to run the previously failed tests

  --failed              Run the tests that failed in the last test run.

Whereas, in the above case, it runs all the tests again.

C:\Python3\NOSE_Tests>nosetests test_even.py  --failed -v
#1 test_even.test_even1 ... ok
#2 test_even.test_even2 ... ok
#3 test_even.test_even3 ... ok
#4 test_even.test_even4 ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.005s

OK

Observation :- --failed is not serving what it is expected to i.e. to re-run the tests that are failed from previous run. Rather runs all the tests in the module. which questions the existence of --failed option.