Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unit Testing Set Up and Use
#2
(Jan-08-2024, 05:17 PM)RockBlok Wrote: Hello again,

I found the unittest documentation and put together this simple scenario based on a tutorial I'm working through.

My question: Is it possible to test a single case instead of both?

Ie.. if I wanted to choose just to run the test_True case. I see there are test skip options in the documentation, I couldn't find anything to test only a specific case.

import unittest

def isDivisible(x, y):
    #is x evenly divisible by y?
    return x % y == 0

class Bool_Unit_Testing(unittest.TestCase):
    def test_True(self):
        self.assertEqual(isDivisible(2,2),True)
    def test_False(self):
        self.assertEqual(isDivisible(2,3),False)
    
if __name__ == "__main__":
    unittest.main()
Have you tried command line interface from documentation? https://docs.python.org/3/library/unitte...-interface
python -m unittest file_name.class_name.function_name
essentially how you call it.
RockBlok likes this post
Reply


Messages In This Thread
Unit Testing Set Up and Use - by RockBlok - Jan-08-2024, 05:17 PM
RE: Unit Testing Set Up and Use - by sgrey - Jan-08-2024, 05:52 PM
RE: Unit Testing Set Up and Use - by deanhystad - Jan-08-2024, 07:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove function and unit test ftg 5 3,695 Jan-07-2020, 03:10 PM
Last Post: ndc85430
  Odd Unit Test Behavior ichabod801 3 2,689 Jan-02-2020, 03:34 PM
Last Post: ichabod801
  Define unit of measure of a number doug2019 3 2,476 Oct-15-2019, 03:43 PM
Last Post: jefsummers
  Unit testing - AssertRaises kerzol81 3 4,725 Oct-07-2019, 10:35 AM
Last Post: buran
  unit testing a method that asks two user inputs() in console gebel 0 2,196 Apr-03-2019, 07:59 PM
Last Post: gebel
  unit test roll die saladgg 5 4,288 Nov-06-2018, 11:39 PM
Last Post: stullis
  Would you unit test __init__ method? kilthar 1 31,327 Oct-18-2017, 05:31 PM
Last Post: snippsat
  Unit testing mp3909 1 2,699 Oct-15-2017, 03:48 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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