문제

I don't understand something, with the python unittest discover. I made this project:

project/
    __init__.py
    src/
        __init__.py
        criteria.py
    tests/
        __init__.py
        criteria_test.py

And to be able to know if I loaded the test correctly I ensure myself to make it fail with the code below

# coding: utf-8
import unittest

class TestCriteria(unittest.TestCase):
    def setUp(self):
        pass
    def test_criteriaFailure(self):
        self.assertTrue(False)

When I do the command in the command-line, I'm at the file project (the root of my packages), I guess everything can be imported.

I tried:

python -m unittest discover
python -m unittest discover -s tests -p '*_test.py'

but it always return me this output:

Ran 0 tests in 0.000s

Ok

I'd like to understand how to use this feature (I'm using python3.2.3) without having to download and install Nose.

Thanks you

도움이 되었습니까?

해결책

Is there anything in your tests/__init__.py file?

I'm looking into the source of unittest (Python's all open source, and very readable -- you can do it too :) ), because I'm more familiar with the Django test runner, but it is likely that your __init__.py file should at least have a line that looks like this:

from criteria_test import *
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top