[py-dev] Call py.test.cmdline.main() from a python script
Hello, I'm using py.test to run my unit tests for STOQ 2 [1] project. To run my tests I can execute py.test script, but I nedd to call py.test from a python script that initalize database and executes some doctests using doctest module. To make this, I add this simple code inside my script: +import py +py.test.cmdline.main() My enviroment uses simbolic links from package/module to a directory on my PYTHONPATH. And after using my runtests.py script with these lines, py.test dont import my test modules correctly. (see traceback log attached) Anohter member of STOQ2 staff, Johan Dahlin <jdahlin@async.com.br>, verify the problem and propose a one line patch to this problem, and I'm send this patch attached too. Thanks, 1. STOQ2 is a Open Source Reatail System written in python and uses: - pygtk - kiwi (MVC framework on top of pygtk) - SQLObject - py.test (pylib) - twisted component model -- Rudá Porto Filgueiras
Hello Rudá, I submitted this patch (r20499) to py-lib. It should solve your problem. --- py/path/local/local.py (revision 20475) +++ py/path/local/local.py (working copy) @@ -372,7 +372,8 @@ if ensuresyspath: self._prependsyspath(pkgpath.dirpath()) pkg = __import__(pkgpath.basename, None, None, []) - assert py.path.local(pkg.__file__).relto(pkgpath) + assert py.path.local(pkg.__file__).realpath().relto( + pkgpath.realpath()) if hasattr(pkg, '__package__'): modname = pkg.__package__.getimportname(self) assert modname is not None, "package %s doesn't know %s" % ( I didn't submit your patch, because it breaks the expected behavior of py.path.local when working with symbolic links. Example:
import py py.path.local('file').ensure() local('.../file') py.path.local('symlink').mksymlinkto(py.path.local('file')) py.path.local().listdir() [local('.../file'), local('.../symlink')] py.path.local().join('symlink') local('.../symlink') py.path.local('symlink') local('.../file')
Is that your svn repository? http://svn.async.com.br/cgi-bin/viewcvs.cgi/Stoq2/?rev=804 Just curious, because I couldn't find any py.test tests ;-) Jan
2005/12/1, Jan Balster <jan@balster.info>:
Hello Rudá, Hi.
I submitted this patch (r20499) to py-lib. It should solve your problem.
--- py/path/local/local.py (revision 20475) +++ py/path/local/local.py (working copy) @@ -372,7 +372,8 @@ if ensuresyspath: self._prependsyspath(pkgpath.dirpath()) pkg = __import__(pkgpath.basename, None, None, []) - assert py.path.local(pkg.__file__).relto(pkgpath) + assert py.path.local(pkg.__file__).realpath().relto( + pkgpath.realpath()) if hasattr(pkg, '__package__'): modname = pkg.__package__.getimportname(self) assert modname is not None, "package %s doesn't know %s" % (
Thanks!
I didn't submit your patch, because it breaks the expected behavior of py.path.local when working with symbolic links.
Example:
import py py.path.local('file').ensure() local('.../file') py.path.local('symlink').mksymlinkto(py.path.local('file')) py.path.local().listdir() [local('.../file'), local('.../symlink')] py.path.local().join('symlink') local('.../symlink') py.path.local('symlink') local('.../file')
Ok! I test with your patch and everything works fine!
Is that your svn repository? http://svn.async.com.br/cgi-bin/viewcvs.cgi/Stoq2/?rev=804 Just curious, because I couldn't find any py.test tests ;-)
This is the tests folder, but some tests will be commited sonn. http://svn.async.com.br/cgi-bin/viewcvs.cgi/stoq/trunk/stoq/tests/ This is the svn repository: svn://www.async.com.br/stoq/trunk -- Rudá Porto Filgueiras Empresa Livre http://www.empresalivre.com.br
participants (2)
-
Jan Balster -
Ruda Filgueiras