R: [Eric] Help Unit testing

Cantoni Massimiliano massimiliano.cantoni at insiel.it
Wed Jun 27 08:13:05 BST 2007


I thank you very much for the quick response.

I tried what you suggested but I still have some problems:

I added the following statement to my codetestcase.py

import sys
import os
sys.path.insert(0,os.path.abspath("."))

and now run and debug scripts are working because I can set their working directories to project

To make work also unit test I added the following to UnitTestDialog.py of Eric4
Just after line 205
Project=e4App().getObject("Project")
#add
	os.chdir(project.getProjectPath())
#end add

Now it is working also unit testing...

But I do not like so much this solution because I need to write the first statement in every test
And i need to write extracode to be sure the statement is not inserted twice or more times.
It could be very interesting if i could use something like pydev source directory which is
A path linked to my project which unittest, run and debug add to sys.path before launching the program.

Am I saying nonsense ? Is this the correct approach?

Again thank for your attention

Massimiliano Cantoni

-----Messaggio originale----- 
Da: Detlev Offenbach [mailto:detlev at die-offenbachs.de] 
Inviato: martedì 26 giugno 2007 19.04
A: eric at riverbankcomputing.com
Cc: Cantoni Massimiliano
Oggetto: Re: [Eric] Help Unit testing

On Montag, 25. Juni 2007, Cantoni Massimiliano wrote:
> Dear List users,
>
> I am working on the new version of Eric4 on my Gentoo Linux machine.
> I have already worked with Python using Eclipse PyDev but I found it 
> elegant but not very responsive.
> I switched to Eric due to Python native implementation and QT4 
> features which I like very much.
> I like very much Eric features but now I am facing the following
> problem:
> My project directory structure is something like this:
>
> MyProjectRoot
> 	src
> 		mypackage
> 			mycode.py
> 			__init__.py
> 		__init__.py
> 	test
> 		mypackage
> 			__init.py
> 			mycodetestcase.py
> 		__init__.py
>
> Now if I run unittest from test/mypackage/mycodetestcase.py, it 
> complains it does not find a class Defined in my src/package/mycode 
> even if I used using src.mypackage.mycode import myclass.
>
> I think the reason is due to the fact UnitTest is using as working 
> directory test/mypackage/...
> It is possible to add a working dir like MyProjectRoot to che 
> enviroment?
>
> Am I doing something wrong?
>
> Could someone point me to the right direction?
>
> Thank you for your attention
>
> Massimiliano Cantoni
>
>
>
> _______________________________________________
> Eric mailing list
> Eric at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/eric

In your initialization routine you could add the path to src to sys.path.

import sys
sys.path.insert(0, <path_to_src>)

Detlev
--
Detlev Offenbach
detlev at die-offenbachs.de



More information about the Eric mailing list