Alex Rivera | Logout

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

Asked 2011-11-08T08:34:27.937
56

I've written a specialized HTML parser, that I want to unit test with a couple of sample webpages I've downloaded.

In Java, I've used class resources, to load data into unit tests, without having to rely on them being at a particular path on the file system. Is there a way to do this in Python?

I found the doctest.testfile() function, but that appears to be specific to doctests. I'd like to just get a file handle, to a particular HTML file, which is relative to the current module.

Thanks in advance for any suggestions!

Edit
Report

1 Answer

1

I guess your task boils down to what's given here to get the current file. Then extend that path by the path to you HTML file and open it.

answered 2011-11-08T09:50:37.353

Your Answer