Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unit Testing Set Up and Use
#1
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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()
Reply
#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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
1
python -m unittest file_name.class_name.function_name
essentially how you call it.
RockBlok likes this post
Reply
#3
Testing is easier when you have an IDE with a test manager. You should also look at pytest. I've used both and like pytest more.
RockBlok likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing unit test results into a text file ateestructural 3 6,952 Nov-15-2020, 05:41 PM
Last Post: ateestructural
  Remove function and unit test ftg 5 5,235 Jan-07-2020, 03:10 PM
Last Post: ndc85430
  Odd Unit Test Behavior ichabod801 3 3,488 Jan-02-2020, 03:34 PM
Last Post: ichabod801
  Define unit of measure of a number doug2019 3 3,189 Oct-15-2019, 03:43 PM
Last Post: jefsummers
  Unit testing - AssertRaises kerzol81 3 8,549 Oct-07-2019, 10:35 AM
Last Post: buran
  unit testing a method that asks two user inputs() in console gebel 0 2,637 Apr-03-2019, 07:59 PM
Last Post: gebel
  unit test roll die saladgg 5 5,438 Nov-06-2018, 11:39 PM
Last Post: stullis
  Would you unit test __init__ method? kilthar 1 33,998 Oct-18-2017, 05:31 PM
Last Post: snippsat
  Unit testing mp3909 1 3,256 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