From: Arfrever Frehtes Taifersar Arahesis <arfrever.fta@gmail.com>
To: gentoo-python@lists.gentoo.org
Subject: Re: [gentoo-python] recent trend of django-foo tests
Date: Mon, 3 Jun 2013 09:05:04 +0200 [thread overview]
Message-ID: <201306030905.07511.Arfrever.FTA@gmail.com> (raw)
In-Reply-To: <CAJ0EP41qbxgqPJhkr4G1mmMEoL2rhEG9zi69imVDSwiR0YyjQQ@mail.gmail.com>
[-- Attachment #1: Type: Text/Plain, Size: 2059 bytes --]
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
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
prev parent reply other threads:[~2013-06-03 7:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-20 9:05 [gentoo-python] recent trend of django-foo tests IAN DELANEY
2013-05-20 9:18 ` Nikolaj Sjujskij
2013-05-20 17:36 ` IAN DELANEY
2013-05-21 8:56 ` Nikolaj Sjujskij
2013-05-21 17:35 ` IAN DELANEY
2013-05-21 10:42 ` Nikolaj Sjujskij
2013-05-30 19:34 ` Mike Gilbert
2013-06-03 7:05 ` Arfrever Frehtes Taifersar Arahesis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201306030905.07511.Arfrever.FTA@gmail.com \
--to=arfrever.fta@gmail.com \
--cc=gentoo-python@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox