473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: unittest: which directory structure?

In article <87************@physik.rwth-aachen.de>,
Torsten Bronger <br*****@physik.rwth-aachen.dewrote:
Hallöchen!

I try to port my doctests to unittest. I've found good turorials
about *writing* unit tests but not about organising the files.

What's the best way to arrange the test source files? I made a
directory called "tests" on the same level as my package, with
(roughly) one test module per package module and wanted to call each
of them from my Makefile or from some sort of root test module.
When I first started using unittest, I did the same thing you did -- I put
the test files in some other directory. This forced me into having to play
the same sorts of tricks you're playing with sys.path so you could import
your modules into the test framework. It also turned out to be more work
for me during normal development, having to go into one directory to edit a
test, then into another to edit the class being tested.

Ultimately, I've come to the conclusion that just putting the production
code and tests in the same directory is easier.

Your next decision is how to name the files. You could put the tests for
foo.py in test_foo.py, or foo_test.py (or a million other minor variations
on spelling and punctuation). Using a "test_" *prefix* means all the tests
sort to the end of the directory listing, so the production code and the
test code stay separated from each other. Using a _test *suffix*, means
the tests for a given module sort next to the module itself.

This is the sort of decision which, while ultimately unimportant, has the
ability to consume the entire development group in days (if not weeks) of
religious debate. Just pick a style, go with it, and make sure everybody
on the team sticks with the same style.
Jun 27 '08 #1
0 879

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2305
by: Will Stuyvesant | last post by:
I have a unittest testfile like this: ----------------------- test_mod.py --------------------- import sys sys.path.append('..') import unittest import mod class...
12
2562
by: Paul Moore | last post by:
One of the things I really dislike about Unittest (compared, say, to a number of adhoc testing tricks I've used in the past, and to Perl's "standard" testing framework) is that the...
4
1437
by: Lol McBride | last post by:
Hi all, I'm developing an OOP program and trying to be smart by using unittest to help me to catch as many bugs as possible during development.Unfortunately I've hit a snag which I believe is to...
8
1816
by: Remy Blank | last post by:
Hello unittest users, In a project I am working on, I have a series of tests that have to be run as root, and others as a normal user. One solution is to separate the tests into two different...
0
2024
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally...
41
10226
by: Roy Smith | last post by:
I've used the standard unittest (pyunit) module on a few projects in the past and have always thought it basicly worked fine but was just a little too complicated for what it did. I'm starting a...
7
2057
by: Jorgen Grahn | last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so on. All of these use the simplest possible internal layout: a number of classes containing test*() methods, and the good...
24
3048
by: john_sips_tea | last post by:
For writing testcode, it looks like there's three ways that it's typically done: (1). using the doctest module, (2). using the unittest module (i.e. "pyunit"), or else (3). just putting an...
3
3419
by: David Vincent | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hello I'm hoping to get some insight into a situation that seems odd to me. My Python experience is limited; I've just started using the unittest module....
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.