2

This is my code:

import unittest

from sallad.Puppgift import Kundenssallad

class Test_kundenssallad(unittest.TestCase):

    def test_av_objekt(self):
        namn = "Grekisksallad"
        slutpris = 60
        tillval = "gurka"
        kundenssallad = Kundenssallad(namn, slutpris, tillval)
        self.assertIsInstance(kundenssallad, Kundenssallad)
        self.assertEqual(kundenssallad.slutpris, 60)
        self.assertEqual(kundenssallad.tillval, "gurka")

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

Upon running this code in PyCharm, I get:

Testing started at 11:32 ...

Process finished with exit code 0

I expected the program to print something like:

...
----------------------------------------------------------------------
Ran 3 tests in 0.000s

OK

Why do the tests not seem to execute?

3
  • Try with tracing prints to see if your test_av_objekt-method doesn't get past some point, or if it manages to execute to its end. Commented May 23, 2016 at 10:36
  • They execute in the PyCharm Run window, using the test-oriented layout. If you'd like, I can make a little animated gif to show you. Commented May 23, 2016 at 14:38
  • Also, note the nature of the command that is doing the running...PyCharm has Python call /Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py with an argument of your filename. The utrunner.py manages the running of your tests, hence utrunner in the filename. Commented May 23, 2016 at 14:39

1 Answer 1

1

You have not told unittest what test suite to run. pycharm not matching the if name == "main" ? Try add some debug and print name.

Run it something like this:

if __name__ == "__main__":
    unittest.main()
    suite = unittest.TestLoader().loadTestsFromTestCase(Test_kundenssallad)
    unittest.TextTestRunner(verbosity=2).run(suite)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.