Organizing unit test?

R

Roy Smith

Over the years, I've tried different styles of organizing unit tests.

I used to create a test directory and put all my tests there. I would
maintain a one-to-one correspondence between production source and test
source, i.e. the test code for foo.py would be in test/foo.py.

More recently, I've taken to having foo.py and test_foo.py in the same
directory.

My latest experiment is to just put both the production code and the
test code in the same file, ending with

if __name__ == '__main__':
unittest.main()

So, if I import the file, I get the production code as a module, and if
I run it from the command line, it runs the tests. This makes the file
messier, but it makes the directory structure cleaner and (I think)
makes the whole thing easier to edit.

Any of these work. I'm just curious what organizations other people
have used and what the plusses and minuses ended up being.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top