I have an API wrapper class WfcAPI
written in Python 3 which I want to test using PyUnit.
The setUpClass()
for WfcAPI
involves logging in to the external API server. The current functional test implementation has the password obfuscated with Base64 encoding, but this is far from an ideal solution for security reasons.
import unittest
import base64
from pykronos import WfcAPI
class Test(unittest.TestCase):
@classmethod
def setUpClass(self):
password = base64.b64decode("U29tZVBhc3N3b3Jk").decode("utf-8")
self.kronos = WfcAPI("SomeUsername", password)
I want to be able to quickly run functional tests for my API wrapper, but I also want to ensure that my username and password aren't included as part of the code.
How can I setup a Python functional test for actions which require a username and password?
password = input('Enter Passowrd')
– Chindwingetpass
– Kaceypytest
instead ofunittest
? – Lorrianelorrieunittest.TestCase
, in case of asetUp
method, you can define a fixture. Finally, in my opinion.pytest
makes testing simpler and more enjoyable =). – Lorrianelorrie