Question

I am trying to run test with nose and here is project structure:

ForTest
├── test_module
│   └── test_suite.py
└── test_runner.py

test_suite.py contains:

def test_1():
    pass


def test_2():
    pass

and test_runner.py contains next:

import nose

nose.main(argv=['','-v']).run_and_exit()

when I run test_runner.py I have next content in output:

test_suite.test_1 ... ok
test_suite.test_2 ... ok
test_suite.test_1 ... ok
test_suite.test_2 ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.002s

OK

Nose runs tests twice. If I connect myself plugin, I can see, for example, that mehtod addSuccess() calls 4 times. Could you explain me, why do I get this behaviour and how can I prevent it?

Was it helpful?

Solution

You can rename your test_runner.py to runner.py, this way nose does not treat your test runner as a test itself.

OTHER TIPS

If you are using setup_module() and teardown_module() in your test file and define: @with(setup_module,teardown_module)

def test_1():

pass

then you need to remove @with(setup_module,teardown_module) from your file, this is making your tests run twice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top