Re: [Tutor] Import modeuls
On Mon, Jul 21, 2008 at 5:15 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote: > They want me to do one test runner which runs any test... And ideally it > should work on any platform You might want to look at nose or py.test, they both have test runners. I think you can give nose a directory and it will find and run the tests in the directory. http://www.somethingaboutorange.com/mrl/projects/nose/ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import modeuls
On Mon, Jul 21, 2008 at 5:15 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote: > They want me to do one test runner which runs any test... And ideally it > should work on any platform > > When I added something to $PYTHONPATH, they told me to remove it... > > You can set environment variables within python, e.g.: os.environ['PYTHONPATH'] = '/some/path:' + old_path What I don't know is if child processes invoked through os.popen inherit that variable on all platforms. However, the subprocess.Popen object takes an explicit "env" variable for that purpose: http://docs.python.org/lib/node528.html http://docs.python.org/lib/module-subprocess.html So you should be able to use that for the same effect. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import modeuls
They want me to do one test runner which runs any test... And ideally it should work on any platform When I added something to $PYTHONPATH, they told me to remove it... On Mon, Jul 21, 2008 at 12:11 PM, arsyed <[EMAIL PROTECTED]> wrote: > On Mon, Jul 21, 2008 at 4:46 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote: > >> Anyway. another related question. I run tests using the runner.py >> >> It has following syntax >> sys.path.insert(path) >> os.popen("python module to run") >> >> Will the python runned from the file see new path? >> >> >> > I'm not sure but I don't think so. Try and see what happens. > > I think to get that behavior, you want to set the PYTHONPATH environment > variable instead. Then, I believe the child process will inherit the parent > process's environment variable. If that doesn't work, look into the > subprocess module which takes an explicit env parameter for the Popen class > in order to accomplish this. > > It's probably easier just to set PYTHONPATH in your shell and then run your > scripts so all programs will have access to it. > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import modeuls
On Mon, Jul 21, 2008 at 3:46 AM, Oleg Oltar <[EMAIL PROTECTED]> wrote: > If I am adding, __init__.py it still doesn't import anything. > Do I have add the import (from sampletest import EmailWithoutA) in my init > file? > > I didn't notice this before, but I don't think python does tilde expansion in sys.path. Try using an absolute path, for example: sys.path.insert(0, "~/folder") to sys.path.insert(0, "/home/user/folder') ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import modeuls
If I am adding, __init__.py it still doesn't import anything. Do I have add the import (from sampletest import EmailWithoutA) in my init file? On Mon, Jul 21, 2008 at 1:28 AM, arsyed <[EMAIL PROTECTED]> wrote: > On Sun, Jul 20, 2008 at 12:46 PM, Oleg Oltar <[EMAIL PROTECTED]> > wrote: > >> Hi >> I need to import several modules from many folders which has subfolders >> >> ~/folder/tests/sampletest.py >> ~/folder/suites/samplesuit.py >> >> a suit uses tests from tests folder. I need to import them somehow from >> tests folder. I added ~/folder to PYTHONPATH in my test_runner: >> >> >> import sys >> import os >> >> sys.path.insert(0, "~/folder") >> os.popen("python2.5 %s" %sys.argv[1]) >> >> But when trying to import module in the samplesuite file: >> >> from tests.sampletest.EmailWithoutA import EmailWithoutA >>> >> >> But I getting ImportError: No module named >> >> Please help >> >> > > Do you have an __init__.py file in the tests and suites directories? > > More on that here: > > http://docs.python.org/tut/node8.html > > "The __init__.py files are required to make Python treat the directories > as containing packages; this is done to prevent directories with a common > name, such as "string", from unintentionally hiding valid modules that > occur later on the module search path. In the simplest case, __init__.pycan > just be an empty file, but it can also execute initialization code for > the package or set the __all__ variable, described later." > > > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import modeuls
On Sun, Jul 20, 2008 at 12:46 PM, Oleg Oltar <[EMAIL PROTECTED]> wrote: > Hi > I need to import several modules from many folders which has subfolders > > ~/folder/tests/sampletest.py > ~/folder/suites/samplesuit.py > > a suit uses tests from tests folder. I need to import them somehow from > tests folder. I added ~/folder to PYTHONPATH in my test_runner: > > > import sys > import os > > sys.path.insert(0, "~/folder") > os.popen("python2.5 %s" %sys.argv[1]) > > But when trying to import module in the samplesuite file: > > from tests.sampletest.EmailWithoutA import EmailWithoutA >> > > But I getting ImportError: No module named > > Please help > > Do you have an __init__.py file in the tests and suites directories? More on that here: http://docs.python.org/tut/node8.html "The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as "string", from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later." ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor