[TIP] I have some data files I want to use in my tests -- how do I specify where they are?
C. Titus Brown
ctb at msu.edu
Sun Dec 20 08:46:29 PST 2009
On Sun, Dec 20, 2009 at 11:43:19AM -0500, Matthew Wilson wrote:
> I'm writing some code to extract and yield some attachments out of
> email messages. I have a file named email_parsers.py and another file
> in a tests/ subdirectory named test_email_parsers.py
>
> I have a few email messages saved as text files. These files are in
> that tests/ directory.
>
> In my test code, I want to know how to open those email files. Should
> I use something like os.dirname(__file__)?
that's what I use -- I calculate everything relative to the Python file using
the data.
> I know I won't always run my tests from the tests/ subdirectory
...so this does't matter :)
--titus
--
C. Titus Brown, ctb at msu.edu
More information about the testing-in-python
mailing list