How to load data from a file, for a unit test, in python?

To load data from a file in a unittest, if the testdata is on the same dir as unittests, one solution :

TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), 'testdata.html')


class MyTest(unittest.TestCase)

   def setUp(self):
       self.testdata = open(TESTDATA_FILENAME).read()

   def test_something(self):
       ....

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)