473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

wrestling with unittest paths..needs suggestions

In my enthusiasm of separating my unittests from my business logic modules, I encounter some problems in my path setting. Can solve them, but so ugly. Needs suggestions in the right way to do it.
This is my problem.
path to main class... say:

path = /home/workspace/src/foo
There is a module Foo.py
/home/workspace/src/foo/Foo.py

My unittest is in:
/home/workspace/src/test/foo
so:
/home/workspace/src/test/foo/FooTest.py

Now, in order to test Foo in FooTest, I added the path to Foo.py in FooTest:

### FooTest.py ###
import os, sys
testpath = os.path.abspath('/home/workspace/src/foo')
sys.path.append(testpath)

Well, it works but if I have to do that for every test module that I write..
Very nasty..

Also, if I would like to write an AllTests.py in /home/python/test/, the solutions of finding the paths to my business logic should still work of course.

So I tried to look around for better solutions, like the use of __init__.py but just can't get it to work without the ugly path setting in my unittest module.

My hope is that someone here can tell me what THE correct solution is here.

Thanks in advance,
Vincent

Jul 18 '05 #1
2 1189
Hello Vincent,
path to main class... say:

path = /home/workspace/src/foo
There is a module Foo.py
/home/workspace/src/foo/Foo.py

My unittest is in:
/home/workspace/src/test/foo
so:
/home/workspace/src/test/foo/FooTest.py Usually the `test' directory is under the source directory
(/home/workspace/src/foo/test), this simplifies things.
import os, sys
testpath = os.path.abspath('/home/workspace/src/foo')
sys.path.append(testpath)

Well, it works but if I have to do that for every test module that I write..
Very nasty..

Have a look at python's test suite for a good example
(/usr/lib/python23/test). There is one `test_support.py' module that
each test import. If you need you can fix the path in this module only.
If you use foo/test then just write `sys.path.append("..")' in
test_support.py

HTH.
Miki
Jul 18 '05 #2
Hello Vincent,
path to main class... say:

path = /home/workspace/src/foo
There is a module Foo.py
/home/workspace/src/foo/Foo.py

My unittest is in:
/home/workspace/src/test/foo
so:
/home/workspace/src/test/foo/FooTest.py Usually the `test' directory is under the source directory
(/home/workspace/src/foo/test), this simplifies things.
import os, sys
testpath = os.path.abspath('/home/workspace/src/foo')
sys.path.append(testpath)

Well, it works but if I have to do that for every test module that I write..
Very nasty..

Have a look at python's test suite for a good example
(/usr/lib/python23/test). There is one `test_support.py' module that
each test import. If you need you can fix the path in this module only.
If you use foo/test then just write `sys.path.append("..")' in
test_support.py

HTH.
Miki

Jul 18 '05 #3

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

Similar topics

4
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...
0
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...
4
by: Helge Stenstroem | last post by:
Say I have a function def f(filename): result = openFileAndProcessContents(filename) return result Can that function be unit tested without having a real file as input? Something along the...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.