[PATCH] Allow tests to run even if postgres isn't installed / configured

142 views
Skip to first unread message

Michael Diamond

unread,
Jul 23, 2012, 6:51:20 PM7/23/12
to we...@googlegroups.com
On a clean checkout of web.py and a fairly standard Python 2.7 install I see the following behavior when I try to run tests (tracebacks truncated for space):

$ python test/alltests.py
Unable to import psycopg2 (ignoring PostgresTest)
Unable to import pysqlite2.dbapi2 (ignoring SqliteTest_pysqlite2)
No module named MySQLdb (ignoring MySQLTest)
Unable to import psycopg (ignoring PostgresTest_psycopg)
Unable to import pgdb (ignoring PostgresTest_pgdb)
No module named DBUtils(ignoring testPooling)
..................................................................................................................................http://0.0.0.0:8080/
...EEEE....
======================================================================
ERROR: testBadSessionId (session.DBSessionTest)
----------------------------------------------------------------------
....
ImportError: Unable to import psycopg2 or psycopg or pgdb

class SessionTest(webtest.TestCase):
======================================================================
ERROR: testParallelSessions (session.DBSessionTest)
----------------------------------------------------------------------
....
ImportError: Unable to import psycopg2 or psycopg or pgdb

======================================================================
ERROR: testRedirect (session.DBSessionTest)
----------------------------------------------------------------------
....
ImportError: Unable to import psycopg2 or psycopg or pgdb

======================================================================
ERROR: testSession (session.DBSessionTest)
----------------------------------------------------------------------
....
ImportError: Unable to import psycopg2 or psycopg or pgdb

----------------------------------------------------------------------
Ran 141 tests in 4.908s

FAILED (errors=4)

These errors, in session.py, occur even though we skip the postgres tests in db.py succesfully, because the same check isn't made in the session test.  Since session behavior is (theoretically) db agnostic, it ought to be ok to switch the test to use SQLite, which will enable more people (Python 2.5 and up) to run the tests successfully without additional system requirements.  With this patch, all tests pass.


diff --git a/test/session.py b/test/session.py
--- a/test/session.py
+++ b/test/session.py
@@ -70,12 +70,12 @@
 class DBSessionTest(SessionTest):
     """Session test with db store."""
     def make_session(self, app):
-        db = webtest.setup_database("postgres")
+        db = webtest.setup_database("sqlite","sqlite3")
         #db.printing = True
         db.query(""
             + "CREATE TABLE session ("
             + "    session_id char(128) unique not null,"
-            + "    atime timestamp default (current_timestamp at time zone 'utc'),"
+            + "    atime timestamp default (datetime('now','utc')),"
             + "    data text)"
         )
         store = web.session.DBStore(db, 'session')
@@ -83,7 +83,7 @@
         
     def tearDown(self):
         # there might be some error with the current connection, delete from a new connection
-        self.db = webtest.setup_database("postgres")
+        self.db = webtest.setup_database("sqlite","sqlite3")
         self.db.query('DROP TABLE session')
 
 if __name__ == "__main__":


Michael

Michael Diamond
dim...@gmail.com
www.DigitalGemstones.com

Michael Diamond

unread,
Aug 2, 2012, 1:12:36 PM8/2/12
to we...@googlegroups.com

Any thoughts on this from the developers? Haven't heard anything about this or my email about making web.py Python 3 compatible.

I'm interested in contributing in these and other areas, but I want to confirm my efforts are desired.

Michael

---

Michael Diamond

Sent from my phone - please excuse the brevity.

Anand Chitipothu

unread,
Aug 2, 2012, 1:20:36 PM8/2/12
to we...@googlegroups.com
On Thu, Aug 2, 2012 at 10:42 PM, Michael Diamond <dim...@gmail.com> wrote:
> Any thoughts on this from the developers? Haven't heard anything about this

Sorry for the delay Michael. Thanks for the fix. I've pushed it now.

> or my email about making web.py Python 3 compatible.
>
> I'm interested in contributing in these and other areas, but I want to
> confirm my efforts are desired.

They are very much desired. Please share your ideas about python3 compatibility.

Anand

Michael Diamond

unread,
Aug 2, 2012, 1:34:40 PM8/2/12
to we...@googlegroups.com

On Aug 2, 2012 1:21 PM, "Anand Chitipothu" <anand...@gmail.com> wrote:
>
> On Thu, Aug 2, 2012 at 10:42 PM, Michael Diamond <dim...@gmail.com> wrote:
> > Any thoughts on this from the developers? Haven't heard anything about this
>
> Sorry for the delay Michael. Thanks for the fix. I've pushed it now.

No worries, glad it's helpful.

>
> > or my email about making web.py Python 3 compatible.
> >
> > I'm interested in contributing in these and other areas, but I want to
> > confirm my efforts are desired.
>
> They are very much desired. Please share your ideas about python3 compatibility.

I posted some details of my initial thoughts on the 22nd, but two immediate action items were to update the wsgiserver code from CherryPy as that is now Python 2/3 compatible, and to identify how to best upgrade to Python 3's unicode handling (moving encoding/decoding to a python 2 only module, perhaps) since that was the biggest issue I ran into with my first attempt.

Anand Chitipothu

unread,
Aug 2, 2012, 1:46:28 PM8/2/12
to we...@googlegroups.com
I think we should start depending on cherrypy-wsgiserver instead of
shipping a copy with web.py. When we started using it, it was not
available on pypi.

cherrypy-wsgiserver is not available for Python3, at least on pypi. We
should provide alternate implementation of dev server using wsgiref.

Anand

Anand Chitipothu

unread,
Aug 2, 2012, 1:56:55 PM8/2/12
to we...@googlegroups.com
>> I posted some details of my initial thoughts on the 22nd, but two immediate
>> action items were to update the wsgiserver code from CherryPy as that is now
>> Python 2/3 compatible, and to identify how to best upgrade to Python 3's
>> unicode handling (moving encoding/decoding to a python 2 only module,
>> perhaps) since that was the biggest issue I ran into with my first attempt.
>
> I think we should start depending on cherrypy-wsgiserver instead of
> shipping a copy with web.py. When we started using it, it was not
> available on pypi.
>
> cherrypy-wsgiserver is not available for Python3, at least on pypi. We
> should provide alternate implementation of dev server using wsgiref.

One of the burdens web.py carries is python2.3 compatibility. When I
last heard, Python 2.3 was still supported on Redhat servers. It might
have changed now. Anybody knows what is the status now?

Anand

Zhang Huangbin

unread,
Aug 2, 2012, 8:41:53 PM8/2/12
to we...@googlegroups.com


On Friday, August 3, 2012 1:56:55 AM UTC+8, Anand wrote:

One of the burdens web.py carries is python2.3 compatibility. When I
last heard, Python 2.3 was still supported on Redhat servers. It might
have changed now. Anybody knows what is the status now?


Red Hat Enterprise Linux (RHEL) 4 ships Py2.3, it was released in 2005, and should be end of life on Feb 29 2012, but Red Hat announced to extend all RHEL life cycle for 3 more years, so it will be end of life on Feb 28 2015.

Red Hat Enterprise Linux 5 ships Py2.4.

You can find RHEL life cycle on this page:

Personally, it's ok for me to drop py2.3 support.
Reply all
Reply to author
Forward
0 new messages