Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python unittest discover

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.

like image 507
HexaGridBrain Avatar asked Jul 31 '26 22:07

HexaGridBrain


1 Answers

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 *
like image 125
Ian Clelland Avatar answered Aug 02 '26 10:08

Ian Clelland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!