I attach a reworked patch with my comments plus a small fix that let's you
run python setup.py test even if you don't have pylib installed.

2008/11/23 Fabian Seoane <[EMAIL PROTECTED]>

> Ondrej Certik wrote:
>
>> This is important, because the new py.test breaks sympy (import py works,
>> but
>> not the later imports). This patch should fix it.
>> ---
>>  sympy/utilities/pytest.py |    9 ++++-----
>>  1 files changed, 4 insertions(+), 5 deletions(-)
>>
>> diff --git a/sympy/utilities/pytest.py b/sympy/utilities/pytest.py
>> index 5919697..c321b5f 100644
>> --- a/sympy/utilities/pytest.py
>> +++ b/sympy/utilities/pytest.py
>> @@ -6,7 +6,10 @@
>>  import sys
>>   try:
>> -    import py
>> +    # tested with py-lib 0.9.0
>> +    from py.__.test.outcome import Outcome, Passed, Failed, Skipped
>> +    from py.__.test.terminal.terminal import TerminalSession
>> +    from py.test import skip
>>     disabled = False
>>  except ImportError:
>>     disabled = True
>> @@ -43,11 +46,7 @@ if disabled:
>>     def skip(str):
>>         raise Skipped(str)
>>  else:
>> -    # tested with py-lib 0.9.0
>> -    from py.__.test.outcome import Outcome, Passed, Failed, Skipped
>> -    from py.__.test.terminal.terminal import TerminalSession
>>     from time import time as now
>> -    from py.test import skip
>>       __all__ = ['XFAIL']
>>
>>
>
>
> It's fine, but I would suggest putting a print statement inside the except
> bloc, something like "print 'Could not load pylib, using built-in  test lib
> instead. Having pylib is greatly recommended etc.'"
>
> Also, would be nice to give the disabled variable a more meaningful name,
> something like USE_PYLIB
>
>


-- 
Fabian, http://fseoane.net/blog/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patches@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en
-~----------~----~----~----~------~----~------~--~---

From c11d48b622e27b0c15936268a72dc7d95742e0d6 Mon Sep 17 00:00:00 2001
From: Ondrej Certik <[EMAIL PROTECTED]>
Date: Fri, 21 Nov 2008 11:14:58 +0100
Subject: [PATCH] move all py.test imports into try/except clause (#1210)

This is important, because the new py.test breaks sympy (import py works, but
not the later imports). This patch should fix it.
---
 setup.py                  |   10 +---------
 sympy/utilities/pytest.py |   16 ++++++++--------
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/setup.py b/setup.py
index 813ea37..e2363e3 100755
--- a/setup.py
+++ b/setup.py
@@ -165,15 +165,7 @@ class test_sympy(Command):
         pass
 
     def run(self):
-        try:
-            import py as pylib
-        except ImportError:
-            print """In order to run the tests, you need codespeak's py.lib
-            web page: http://codespeak.net/py/dist/
-            If you are on debian systems, the package is named python-codespeak-lib
-            """
-            sys.exit(-1)
-        pylib.test.cmdline.main(args=["sympy"])
+        sympy.test()
         tdoc = test_sympy_doc(self.args)
         tdoc.run() # run also the doc test suite
 
diff --git a/sympy/utilities/pytest.py b/sympy/utilities/pytest.py
index 5919697..d5e68da 100644
--- a/sympy/utilities/pytest.py
+++ b/sympy/utilities/pytest.py
@@ -6,10 +6,14 @@
 import sys
 
 try:
-    import py
-    disabled = False
+    # tested with py-lib 0.9.0
+    from py.__.test.outcome import Outcome, Passed, Failed, Skipped
+    from py.__.test.terminal.terminal import TerminalSession
+    from py.test import skip
+    USE_PYTEST = True
 except ImportError:
-    disabled = True
+    USE_PYTEST = False
+    print "Could not load pylib. Havin pylib is greatly recommended, see http://codespeak.net/py/dist/ for more info"
 
 def raises(ExpectedException, code):
     assert isinstance(code, str)
@@ -21,7 +25,7 @@ def raises(ExpectedException, code):
         return
     raise Exception("DID NOT RAISE")
 
-if disabled:
+if not USE_PYTEST:
     class XFail(Exception):
         pass
 
@@ -43,11 +47,7 @@ if disabled:
     def skip(str):
         raise Skipped(str)
 else:
-    # tested with py-lib 0.9.0
-    from py.__.test.outcome import Outcome, Passed, Failed, Skipped
-    from py.__.test.terminal.terminal import TerminalSession
     from time import time as now
-    from py.test import skip
 
     __all__ = ['XFAIL']
 
-- 
1.6.0.2

Reply via email to