471,330 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Embedding unit tests in source files?

I'm starting a new project and am thinking of embedding my unit tests
right in the source files. I've used unittest before, and I'm happy
with it, but I've always used it with the source code in one file and
the unit tests in another. I figure if I just put a

if __name__ == '__main__":
import unittest
blah, blah, blah

block at the end of each source file, I'll end up with a cleaner
project structure. I can run the unit tests just by executing each
source file. Any comments from people who have organized their Python
projects this way? Did it work out well?

It seems like what you give up is the ability to aggregate tests in a
hierarchy of test suites. In theory, that sounds like something you
might want to do, but in practice, I've never found it that useful, so
I don't think I'll miss it.

I know about doctest, but I'm happy with unittest and don't see any
reason to change.

Jun 17 '07 #1
0 875

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by newbiecpp | last post: by
2 posts views Thread by Naveen Mukkelli | last post: by
11 posts views Thread by D. Yates | last post: by
72 posts views Thread by Jacob | last post: by
10 posts views Thread by Sean Chambers | last post: by
1 post views Thread by rich_sposato | last post: by
20 posts views Thread by earthwormgaz | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.