在org src中使用unittest
#+begin_src python :session unittest :results output :export none
import unittest
def square(n):
return n ** 2
class MyCase(unittest.TestCase):
def test_a(self):
check = square(3)
self.assertEqual(check, 9)
unittest.main(exit=False)
#+end_src
#+RESULTS:
: .
: ----------------------------------------------------------------------
: Ran 1 test in 0.000s
:
: OK
在使用ipython时效果很好
#+begin_src ipython :session unittest :results output
import unittest
def square(n):
return n ** 2
class MyCase(unittest.TestCase):
def test_a(self):
check = square(3)
self.assertEqual(check, 9)
unittest.main(exit=False)
#+end_src
#+RESULTS:
#+begin_example
E
======================================================================
ERROR: /home/me/ (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute '/home/me/'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
#+end_example
AttributeError: module '__main__' has no attribute '/home/me/'
没有提供任何线索。
事物在ipython shell中正常工作
In [30]: %paste
import unittest
def square(n):
return n ** 2
class MyCase(unittest.TestCase):
def test_a(self):
check = square(3)
self.assertEqual(check, 9)
unittest.main(exit=False)
## -- End pasted text --
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Out[30]: <unittest.main.TestProgram at 0x7f45b55119d0>
可能是什么问题?