Python Forum
How to write test cases for a init function by Unit test in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to write test cases for a init function by Unit test in python?
#3
you have:
class DataSinkConfig():
    DEFAULT_ENTRIES_TABLE = 'entries'
    DEFAULT_OUTLIERS_TABLE = 'outliers'
    DEFAULT_OUTLIERCAUSES_TABLE = 'outlier_causes'
 
    # Note
    def __init__(self, dbconf):
 
        insopt = dbconf.get('insopt')
        if insopt is None:
            self.entries_table_name = self.DEFAULT_ENTRIES_TABLE
            self.outliers_table_name = self.DEFAULT_OUTLIERS_TABLE
            self.outlier_causes_table_name = self.DEFAULT_OUTLIERCAUSES_TABLE
why not just?:
class DataSinkConfig():
    def __init__(self, dbconf):
 
        insopt = dbconf.get('insopt')
        if insopt is None:
            self.entries_table_name = 'entries'
            self.outliers_table_name = 'outliers'
            self.outlier_causes_table_name = 'outlier_causes'
Reply


Messages In This Thread
RE: How to write test cases for a init function by Unit test in python? - by Larz60+ - Feb-24-2020, 12:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Class test : good way to split methods into several files paul18fr 4 525 Jan-30-2024, 11:46 AM
Last Post: Pedroski55
  Unit Testing Set Up and Use RockBlok 2 466 Jan-08-2024, 07:43 PM
Last Post: deanhystad
  How to automate loop test check on Network device jpc230 1 607 Oct-09-2023, 09:54 PM
Last Post: Larz60+
  How to test the high-score in my Python-game Pluviometer 2 611 Oct-02-2023, 06:55 PM
Last Post: deanhystad
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 983 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Better way to write this function SephMon 1 839 Feb-08-2023, 10:05 PM
Last Post: Gribouillis
  Presenting random test questions oradba4u 2 938 Sep-27-2022, 04:23 PM
Last Post: deanhystad
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,077 Sep-19-2022, 02:32 AM
Last Post: Xeno
  How to sort .csv file test log which item first fail and paint color SamLiu 24 5,117 Sep-03-2022, 07:32 AM
Last Post: Pedroski55
  Help with bleak - how to send test to BLE device? korenron 1 1,771 Aug-28-2022, 11:28 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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