Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100246
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ben Finney <ben+python@benfinney.id.au> |
| Newsgroups | comp.lang.python |
| Subject | Re: python unit test frame work |
| Date | Fri, 11 Dec 2015 10:02:07 +1100 |
| Lines | 68 |
| Message-ID | <mailman.122.1449788544.12405.python-list@python.org> (permalink) |
| References | <CACT3xuUOrbdkiEDkDMcVxCO+td4setJMb2TamW5te3FQK8oL0g@mail.gmail.com> <n4c706$g88$1@ger.gmane.org> <CACT3xuUzRn5Sq8V5zqLYx-QFuKkTKJHvcJGLTT9HLSTKPBL_tw@mail.gmail.com> <CACT3xuWxoQdg4P_5GCGVLXEWcDk09sFoROuZ8=Ukox42_kMc_w@mail.gmail.com> <CACT3xuXS5zcppQ4W0dxigi=Pv99doH81_KpttR=+3WSrOuOzzw@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.uni-berlin.de 1LpcL2EykTncmicWdO5IzQcNQVJtvvGQWOxgs8mqqidg== |
| Cancel-Lock | sha1:8TlCDEXdt/pJw96RcysCUfEKJdc= |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'sys': 0.05; '"__main__":': 0.07; '__name__': 0.07; 'subject:test': 0.07; 'exits': 0.09; 'fails.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; 'subject:python': 0.14; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'steps,': 0.16; 'tests)': 0.16; 'try:': 0.18; 'tests': 0.18; 'input': 0.18; 'fit': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; '(which': 0.26; 'header:X-Complaints-To:1': 0.26; 'sense': 0.26; 'module.': 0.27; 'sequence': 0.27; 'function': 0.28; 'skip:( 20': 0.28; 'actual': 0.28; 'raise': 0.29; 'code': 0.30; 'checks': 0.30; 'continuing': 0.32; 'run': 0.33; 'except': 0.34; 'unit': 0.35; 'should': 0.36; 'instead': 0.36; 'subject:work': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'received:org': 0.37; 'means': 0.39; 'test': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'entire': 0.61; 'skip:\xe2 10': 0.70; '8bit%:43': 0.72; '1991': 0.84; '_o__)': 0.84; 'hijacking': 0.84; 'received:125': 0.84; '\xe2\x80\xa6': 0.84; '\xe2\x80\x9cthe': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | jigong.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:100246 |
Show key headers only | View raw
Ganesh Pal <ganesh1pal@gmail.com> writes:
> I have multiple checks if I don't meet them continuing with the main
> program doesn't make sense
That means these are not unit tests (which are isolatable, independent
test cases).
If the tests are best characterised as a sequence of steps, then the
‘unittest’ model (designed for actual unit tests) will not fit well.
You should instead just write a ‘main’ function that calls each test
case in turn and exits when one of them fails.
import sys
from .. import foo_app
def test_input_wibble_returns_lorem(frob):
""" Should process 'wibble' input and result in state 'lorem'. """
frob.process("wibble")
if frob.state != "lorem":
raise AssertionError
def test_input_warble_returns_ipsum():
""" Should process warble' input and result in state 'ipsum'. """
frob.process("warble")
if frob.state != "ipsum":
raise AssertionError
# …
EXIT_STATUS_ERROR = 1
def main(argv):
""" Mainline code for this module. """
process_args(argv)
test_cases = [
test_input_wibble_returns_lorem,
test_input_warble_returns_ipsum,
# …
]
test_frob = foo_app.Frob()
for test_case in test_cases:
try:
test_case(test_frob)
except AssertionError as exc:
sys.stderr.write("Test run failed ({exc})".format(exc=exc))
sys.exit(EXIT_STATUS_ERROR)
if __name__ == "__main__":
exit_status = main(sys.argv)
sys.exit(exit_status)
--
\ “The greatest tragedy in mankind's entire history may be the |
`\ hijacking of morality by religion.” —Arthur C. Clarke, 1991 |
_o__) |
Ben Finney
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: python unit test frame work Ben Finney <ben+python@benfinney.id.au> - 2015-12-11 10:02 +1100
csiph-web