I want to do something simple, which is running tests from another python
program.
What is should do is quite the same as the normal nosetests, so collect
all the test modules and run them.
All the things I've tried until now didn't find/run any tests unfortunately,
and here is the last attempt:
class NoseTestRunner(object):
def egg_runner(self, eggpath):
conf = Config()
# it must be a tuple even if it's not really supported
conf.where = (eggpath, )
return TestProgram(config=conf)
Where I found out in the config module that where is the path where
the test modules should be looked for..
Any idea of what I'm missing?
Thanks,
Andrea
http://readthedocs.org/docs/nose/en/latest/api/core.html#nose.core.run
Or have you already tried nose.run()?
JP
> --
> You received this message because you are subscribed to the Google Groups
> "nose-users" group.
> To post to this group, send email to nose-...@googlegroups.com.
> To unsubscribe from this group, send email to
> nose-users+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nose-users?hl=en.
>
It's actually the same as TestProgram, just exit is set to False, and
I get the same result, something like..
Ok
run 0 tests...
From the same directory running nosetest instead works perfectly, and
I thought I was doing the same thing.
Is there a way to get more debug output from the loader to see what
it's actually looking for and discarding eventually?
(Because it takes quite some time anyway to run the command).
I found the problem, even if not understood yet, and it's in the code
calling
that class, if made more stupid everything works.
I maybe understood, is nose using the sys.argv even as when called from
another python
program.
Because I had something like
run_tests.py -m simple <directory to test>
And I was passing myself <directory to test> as where, but removing
"-m simple" actually works, and more surprisingly also not handling myself
<directory to test> works, so it's clear that someone else is using
the sys.argv after me, how do I avoid that?
Thanks
That worked fine actually thanks, now I have another problem though.
Running from nosetests everything work correctly, but with my own very
stupid
wrapper I get something like:
File
"h:\git_projs\Psi\psi.devsonly\psi\devsonly\test\test_wrapper.py", line
1, in <module>
import psi.devsonly.setup_wrapper as sw
AttributeError: 'module' object has no attribute 'setup_wrapper'
And the wrapper is simply this
class NoseTestRunner(object):
def egg_runner(self, eggpath):
conf = Config()
conf.verbosity = True
return TestProgram(argv=argv[:1], defaultTest=eggpath)
Which makes me think that the importer used is somehow different and
smarter when running nosetests... What can this be then?
Thanks..
Mm no I don't think is the issue, but I found something really
interesting debugging
with PDB.
If I do from the pdb shell:
import psi.devsonly.setup_wrapper
it works
if I do
import psi.devsonly.setup_wrapper as sw
it doesn't with a "module object has no attribute setup_wrapper" , while
they both work perfectly from IPython.
And more strangely they actually work if just running nosetests.
So what can be different in the two cases?
I added a print statement just before it fails to see what it does
(it's this "mod = load_module(part_fqname, fh, filename, desc)"
from the importer.py module by the way).
And I get the following:
Running nosetests
--8<---------------cut here---------------start------------->8---
trying to import psi, None, H:\git_projs\Psi\psi.devsonly\psi, ('', '', 5)
trying to import psi.devsonly, None,
H:\git_projs\Psi\psi.devsonly\psi\devsonly,
('', '', 5)
--8<---------------cut here---------------end--------------->8---
And all the tests run and pass
Running my wrapper (which is simply):
--8<---------------cut here---------------start------------->8---
class NoseTestRunner(object):
def egg_runner(self, eggpath):
conf = Config()
conf.verbosity = 3
return TestProgram(argv=argv[:1], defaultTest=eggpath, config=conf)
--8<---------------cut here---------------end--------------->8---
I get instead:
--8<---------------cut here---------------start------------->8---
running mode simple
trying to import psi, None, H:\git_projs\Psi\psi.devsonly\psi, ('', '', 5)
trying to import psi.devsonly, None,
H:\git_projs\Psi\psi.devsonly\psi\devsonly,
('', '', 5)
trying to import psi.devsonly.bin, None,
H:\git_projs\Psi\psi.devsonly\psi\devso
nly\bin, ('', '', 5)
======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'walk')
----------------------------------------------------------------------
Traceback (most recent call last):
File
"c:\python25\lib\site-packages\nose-0.10.3n1-py2.5-win32.egg\nose\loader.
py", line 364, in loadTestsFromName
addr.filename, addr.module)
File
"c:\python25\lib\site-packages\nose-0.10.3n1-py2.5-win32.egg\nose\importe
r.py", line 39, in importFromPath
return self.importFromDir(dir_path, fqname)
File
"c:\python25\lib\site-packages\nose-0.10.3n1-py2.5-win32.egg\nose\importe
r.py", line 85, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "h:\git_projs\Psi\psi.devsonly\psi\devsonly\test\test_walk.py",
line 3, i
n <module>
import psi.devsonly.walk as w
AttributeError: 'module' object has no attribute 'walk'
--8<---------------cut here---------------end--------------->8---
The only difference is that it tries also to load the bin directory, but
why does it behave in a different way in the first place then?
('got ', 'psi.devsonly.test', None,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test', ('', '', 5))
('got ', 'psi.devsonly.test.other_deps', None,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/other_deps',
('', '', 5))
('got ', 'psi.devsonly.test.other_deps.dep1', None,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/other_deps/dep1',
('', '', 5))
('got ', 'psi.devsonly.test.other_deps.dep2', None,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/other_deps/dep2',
('', '', 5))
('got ', 'psi.devsonly.test.test_analyze', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_analyze.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_analyze.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_checksums', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_checksums.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_checksums.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_dev_main', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_dev_main.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_dev_main.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_egg', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_egg.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_egg.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_environment', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_environment.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_environment.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_history', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_history.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_history.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_imports', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_imports.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_imports.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_pathfixer', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_pathfixer.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_pathfixer.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_problem', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_problem.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_problem.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_remove_eggs', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_remove_eggs.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_remove_eggs.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_utils', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_utils.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_utils.py',
('.py', 'U', 1))
('got ', 'psi.devsonly.test.test_walk', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_walk.py', mode
'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_walk.py', ('.py',
'U', 1))
('got ', 'psi.devsonly.test.test_wrapper', <open file
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_wrapper.py',
mode 'U' at 0x12ddae0>,
'/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/test/test_wrapper.py',
('.py', 'U', 1))
I checked all the values that are passed to the TestProgram class in
Unittest,
and they are all the same.
The only thing which I might think problematic is the different
implementation
of the TestProgram in the different versions of unittest.
These are the two different versions..
Any clue about what could cause the import problems??
# new version
class TestProgram(object):
failfast = catchbreak = buffer = progName = None
def __init__(self, module='__main__', defaultTest=None, argv=None,
testRunner=None, testLoader=loader.defaultTestLoader,
exit=True, verbosity=1, failfast=None, catchbreak=None,
buffer=None):
if isinstance(module, basestring):
self.module = __import__(module)
for part in module.split('.')[1:]:
self.module = getattr(self.module, part)
else:
self.module = module
if argv is None:
argv = sys.argv
self.exit = exit
self.failfast = failfast
self.catchbreak = catchbreak
self.verbosity = verbosity
self.buffer = buffer
self.defaultTest = defaultTest
self.testRunner = testRunner
self.testLoader = testLoader
self.progName = os.path.basename(argv[0])
self.parseArgs(argv)
self.runTests()
# old version
class TestProgram:
def __init__(self, module='__main__', defaultTest=None,
argv=None, testRunner=None, testLoader=defaultTestLoader):
if type(module) == type(''):
self.module = __import__(module)
for part in module.split('.')[1:]:
self.module = getattr(self.module, part)
else:
self.module = module
if argv is None:
argv = sys.argv
self.verbosity = 1
self.defaultTest = defaultTest
self.testRunner = testRunner
self.testLoader = testLoader
self.progName = os.path.basename(argv[0])
self.parseArgs(argv)
self.runTests()