Stefan Falk
Stefan Falk

Reputation: 25387

Getting "No tests were found" when running unittest

If I click "Run 'Unittest for ..'" in PyCharm it prints:

Launching unittests with arguments python -m unittest /home/sfalk/workspace/git/m-search/python/tests/cluster/pipeline/preprocessing.py in /home/sfalk/workspace/git/m-search/python/tests/cluster/pipeline

and reports

No tests were found.

However, if I copy this exact line which PyCharm claims to run, namely

python -m unittest /home/sfalk/workspace/git/m-search/python/tests/cluster/pipeline/preprocessing.py

then I get my expected output.

$ python -m unittest /home/sfalk/workspace/git/m-search/python/tests/cluster/pipeline/preprocessing.py
..
+---+------------+
| _1|          _2|
+---+------------+
|  1|Hello World!|
+---+------------+

.
----------------------------------------------------------------------
Ran 1 test in 4.998s

OK

The run configuration says:

Script path: /home/sfalk/workspace/git/m-search/python/tests/cluster/pipeline/preprocessing.py

Working directory: /home/sfalk/workspace/git/m-search/python/tests/cluster/pipeline

I don't get this ..


It should not matter imho but here's the code of the unit test:

import unittest

from pyspark import SparkContext, SparkConf, SQLContext


class TestPreprocessingText(unittest.TestCase):

    def test_preprocessingText(self):

        conf = SparkConf()
        conf.setMaster('local')
        conf.setAppName('MyApp')
        sc = SparkContext.getOrCreate()

        sql = SQLContext(sc)

        df = sql.createDataFrame(
            [
                (1, 'Hello World!')
            ]
        )

        df.show()


if __name__ == '__main__':
    unittest.main()

Upvotes: 1

Views: 4287

Answers (1)

Zilong Li
Zilong Li

Reputation: 958

Try renaming your test filename following this convention:

app_folder/
    appname.py
    test_appname.py

As shown above, the app you are trying to test and the test file are in the same directory following that naming convention.

Upvotes: 4

Related Questions