2013-05-30 21:34 Mike Gilbert napisaƂ(a): > python -c "code" foo.py does NOT run foo.py. $ cat my_script #!/usr/bin/python import sys import unittest class SomeTests(unittest.TestCase): def test_something(self): self.assertTrue(sys.something > 0) if __name__ == "__main__": unittest.main(verbosity=2) $ diff -u my_script my_module.py $ python my_script test_something (__main__.SomeTests) ... ERROR ====================================================================== ERROR: test_something (__main__.SomeTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "my_script", line 8, in test_something self.assertTrue(sys.something > 0) AttributeError: 'module' object has no attribute 'something' ---------------------------------------------------------------------- Ran 1 test in 0.001s FAILED (errors=1) $ python -m my_module test_something (__main__.SomeTests) ... ERROR ====================================================================== ERROR: test_something (__main__.SomeTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "./my_module.py", line 8, in test_something self.assertTrue(sys.something > 0) AttributeError: 'module' object has no attribute 'something' ---------------------------------------------------------------------- Ran 1 test in 0.001s FAILED (errors=1) $ python -c 'import runpy, sys; sys.something=1; runpy.run_path("my_script", run_name="__main__")' test_something (__main__.SomeTests) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.000s OK $ python -c 'import runpy, sys; sys.something=1; runpy.run_module("my_module", run_name="__main__", alter_sys=True)' test_something (__main__.SomeTests) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.000s OK $ :) -- Arfrever Frehtes Taifersar Arahesis