Python Forum
How to pass a dictionary as an argument inside setup function of unittest
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pass a dictionary as an argument inside setup function of unittest
#2
Passing lists and dictionaries to functions is done using the asterisk and double asterisk syntax respectively. Here is a simple demo program to show you how it works:
def aFunc (param1, param2, param3):
    print("This is param1: {}".format(param1))
    print("This is param2: {}".format(param2))
    print("This is param3: {}".format(param3))

paramDict = {"param1": "I am param1!", "param2": "I am param2!", "param3": "I am param3!"}
aFunc(**paramDict)

print("\n")

paramList = ["I am param1!", "I am param2!", "I am param3!"]
aFunc(*paramList)
Output:
This is param1: I am param1 This is param2: I am param2 This is param3: I am param3 This is param1: I am param1 This is param2: I am param2 This is param3: I am param3
Using the single asterisk syntax on dictionaries passes the keys to the function. Single asterisk also works with tuples.

I hope this helps. I'm going by the title of the thread. I know what unittest is, though I've never used it, I don't know what Appium code is and I am unfamiliar with about half the libraries you're using. If all you needed was to know how to pass dictionaries to functions, here you go.
Reply


Messages In This Thread
RE: How to pass a dictionary as an argument inside setup function of unittest - by keames - May-11-2019, 03:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in using unittest akbarza 2 355 Feb-25-2024, 12:51 PM
Last Post: deanhystad
  mutable argument in function definition akbarza 1 511 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  How to pass encrypted pass to pyodbc script tester_V 0 887 Jul-27-2023, 12:40 AM
Last Post: tester_V
  with open context inside of a recursive function billykid999 1 596 May-23-2023, 02:37 AM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 815 May-02-2023, 08:40 AM
Last Post: Gribouillis
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,132 Dec-25-2022, 03:00 PM
Last Post: askfriends
  passing dictionary to the function mark588 2 1,010 Dec-19-2022, 07:28 PM
Last Post: deanhystad
Question Unwanted execution of unittest ThomasFab 9 2,127 Nov-15-2022, 05:33 PM
Last Post: snippsat
  i want to use type= as a function/method keyword argument Skaperen 9 1,943 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  unittest.mock for an api key silver 3 1,410 Aug-29-2022, 03:52 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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