tox doesn't run the correct code and setting up lib is not reliable

Issue #3356 resolved
Mike Bayer repo owner created an issue

patch, needs further testing:

diff --git a/regen_callcounts.tox.ini b/regen_callcounts.tox.ini
index 056208c..e74ceef 100644
--- a/regen_callcounts.tox.ini
+++ b/regen_callcounts.tox.ini
@@ -12,8 +12,6 @@ deps=pytest
     py{27}-sqla_{cext,nocext}-db_{mysql}: mysql-python
     py{33,34}-sqla_{cext,nocext}-db_{mysql}: pymysql

-usedevelop=False
-sitepackages=True


 commands=
@@ -22,7 +20,11 @@ commands=
    db_{postgresql}: {[base]basecommand} --db postgresql {posargs}
    db_{sqlite}: {[base]basecommand} --db sqlite {posargs}

+# -E     : ignore PYTHON* environment variables (such as PYTHONPATH)
+# -s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE
 setenv=
-   sqla_nocext: DISABLE_SQLALCHEMY_CEXT=1
+    PYTHONPATH=
+    PYTHONNOUSERSITE=1
+    sqla_nocext: DISABLE_SQLALCHEMY_CEXT=1


diff --git a/sqla_nose.py b/sqla_nose.py
index fc55f34..3925fb7 100755
--- a/sqla_nose.py
+++ b/sqla_nose.py
@@ -10,10 +10,9 @@ import sys
 import nose
 import os

-
-for pth in ['./lib']:
-    sys.path.append(
-        os.path.join(os.path.dirname(os.path.abspath(__file__)), pth))
+if not sys.flags.no_user_site:
+    sys.path.insert(0,
+        os.path.join(os.path.dirname(os.path.abspath(__file__)), './lib'))

 # use bootstrapping so that test plugins are loaded
 # without touching the main library before coverage starts
diff --git a/test/conftest.py b/test/conftest.py
index 590b357..7572ecc 100755
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -9,10 +9,9 @@ installs SQLAlchemy's testing plugin into the local environment.
 import sys
 import os

-for pth in ['../lib']:
-    sys.path.append(
-        os.path.join(os.path.dirname(os.path.abspath(__file__)), pth))
-
+if not sys.flags.no_user_site:
+    sys.path.insert(0,
+        os.path.join(os.path.dirname(os.path.abspath(__file__)), './lib'))

 # use bootstrapping so that test plugins are loaded
 # without touching the main library before coverage starts
diff --git a/test/sql/test_query.py b/test/sql/test_query.py
index 08afc32..aaba249 100644
--- a/test/sql/test_query.py
+++ b/test/sql/test_query.py
@@ -79,6 +79,8 @@ class QueryTest(fixtures.TestBase):
         """test that executemany parameters are asserted to match the
         parameter set of the first."""

+        import pdb
+        pdb.set_trace()
         assert_raises_message(
             exc.StatementError,
             r"\(sqlalchemy.exc.InvalidRequestError\) A value is required for "
diff --git a/tox.ini b/tox.ini
index 3b1d2ea..34f40e2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -5,8 +5,15 @@ envlist = full,py26,py27,py33,py34
 deps=pytest
      mock

-sitepackages=True
-usedevelop=True
+# -E     : ignore PYTHON* environment variables (such as PYTHONPATH)
+# -s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE
+setenv=
+    PYTHONPATH=
+    PYTHONNOUSERSITE=1
+
+sitepackages=False
+usedevelop=False
+

 commands=
   python -m pytest {posargs}

Comments (1)

  1. Mike Bayer reporter
    • Fixed the pathing used when tests run; for sqla_nose.py and py.test, the "./lib" prefix is again inserted at the head of sys.path but only if sys.flags.no_user_site isn't set; this makes it act just like the way Python puts "." in the current path by default. For tox, we are setting the PYTHONNOUSERSITE flag now. fixes #3356

    → <<cset f30e35babc63>>

  2. Log in to comment