Python Forum
Ran 0 tests in 0.000s - unittest
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ran 0 tests in 0.000s - unittest
#1
Hi Heart I'm an absolute beginner so please don't kill me if my question is dumb. Angel

I've a new project in Pycharm. The structure is as follows:

project
....tests
........__init__.py
........test_data_reader.py
....data_reader.py

__init__.py is a blank file, data_reader.py reads some csv data and stores ist as: df = pd.read_csv(...).

I tried to set up a unittest file in the tests folder. The file test_data_reader.py contains the following code:


import unittest
from data_reader import *


class TestDataReader(unittest.TestCase):

    def test_ncol(self):
        self.assertEqual(df.shape[1], 4)


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

If I run it i get the following message:

----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK

But shouldn't there be written "Ran 1 tests in 0.000s, OK"?
Does anyone see my error?
Thank you in advance and have a nice day! Smile
Reply
#2
Can you show how you're running the test?
Reply
#3
(Dec-30-2021, 01:37 PM)ndc85430 Wrote: Can you show how you're running the test?

Hi ndc85430, thank you for your reply! I don't use the python console to run the test, if you mean that. Instead, I use PyCharm and choose the right interpreter, the right configurations and click the run button. Or did you mean something else by your question?
I just tried to type "python test_data_reader.py" in the python console in PyCharm and got the following error:

File "<input>", line 1
python test_data_reader.py
^
SyntaxError: invalid syntax
Reply
#4
Well of course you don't run python at the Python shell. You just run that command in a regular OS shell (e.g. Bash, zsh, etc. if you're on Unix)

OK, since you're using PyCharm, can you show what the configuration is? For whatever reason, the test discovery stuff isn't finding your test.
Reply
#5
(Dec-30-2021, 03:28 PM)ndc85430 Wrote: OK, since you're using PyCharm, can you show what the configuration is? For whatever reason, the test discovery stuff isn't finding your test.

Yes, basically, i followed this tutorial for my first steps: https://www.youtube.com/watch?v=56bPIGf4us0. I pretty much did the same thing as the guy explains at 2:12.
My configuration for the test_data_reader.py file is: Python with the script-path of the test_data_reader.py, as Python interpreter i selected Python 3.8 with the environment of the project and Working directory is the path to the project in PyCharm.

I did the same for other files in this project (with the adapted script-path) and it worked fine (also from ... import *).
Reply
#6
What happens if you set the working directory to your tests directory?

Are you able to successfully run your tests from the command line?
Reply
#7
(Dec-30-2021, 07:51 PM)ndc85430 Wrote: What happens if you set the working directory to your tests directory?

Are you able to successfully run your tests from the command line?

Unfortunately, both doesn't work. I will give the code to one of my friends to see if it works on her device. If it works, I will open a new project to see if it the current project or or folder structure is the problem. If it doesn't work on her device...well...I guess I will start from 0 with my unittest file Confused
Thank you very much for your help so far!
Reply
#8
What happens when you run the tests from the command line? I've not written any Python for a while, so are you sure you've written the test class correctly? It looks fine to me.

Also, there's no need to quote the previous post in full. It just wastes space.
Reply
#9
I get the error: "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings". I will try the advices suggested in https://stackoverflow.com/questions/6534...soft-store.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in using unittest akbarza 2 331 Feb-25-2024, 12:51 PM
Last Post: deanhystad
Question Unwanted execution of unittest ThomasFab 9 2,073 Nov-15-2022, 05:33 PM
Last Post: snippsat
  unittest.mock for an api key silver 3 1,399 Aug-29-2022, 03:52 PM
Last Post: ndc85430
Sad Problem with Unittest mhanusek 1 3,769 Nov-12-2020, 04:58 PM
Last Post: Gribouillis
  Unittest et patch mad31 2 2,139 Aug-09-2020, 06:16 AM
Last Post: mad31
  Unusual things to do with unittest/HTMLTestRunner AndyHolyer 0 2,148 Jul-29-2020, 02:43 PM
Last Post: AndyHolyer
  VSCode not able to discover tests rpk2006 5 10,931 Jul-15-2020, 06:03 AM
Last Post: ndc85430
  Test a class function via "unittest " Penguin827 1 1,625 Jul-10-2020, 08:31 AM
Last Post: Gribouillis
  StopIteration exception when mock PostgreSQL connection in several tests igor87z 1 2,930 Jun-10-2020, 06:16 PM
Last Post: ibreeden
  How to use unittest module ? binhduonggttn 1 2,053 Feb-17-2020, 03:28 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020