I frequently use the Mock library for unit testing in python. I needed a quick reference for my favorite functionality and couldn’t find one. I decided to make a lighthearted attempt at writing one while watching Kung Fu Panda on the telly. I hope others find it useful. Before I start, here is the list of my favorites: Mock classes Mock class methods Mock instances Mock instance methods Configurab
MagicMock は mock.Mock のサブクラスで、薄いラッパーです。 >>> from mock import Mock, MagicMock >>> issubclass(MagicMock, Mock) True >>> list(set(dir(MagicMock)) - set(dir(Mock))) ['_mock_set_magics'] MagicMock を使えば、クラスだろうがオブジェクトだろうがメソッドだろうが関数だろうが、何でもモックオブジェクトで置き換えて、その振る舞いを自由にシュミレートすることができます。 まず、一番シンプルにモックを使う方法は、直接 MagicMock オブジェクトを代入するやり方です。 models.py(置換対象クラス) import random class User(object): def __init__(self, na
昨日 XMLTestRunnerで標準出力を結果に出すやつを書いたら、@aodag 先生から、こんな指摘をもらった。 @aodag 「なんで自分XMLTestRunnerなんて使ってん? noseならオプションで標準出力の制御できんのに。」 という事で、使った事のある noseのオプションの覚え書き。 昨日のヤツ XMLTestRunner の 標準出力(stdout) どこいった? - Study08.net 対シンバシ殲滅用人型機動兵器 標準出力の表示(-s or --nocapture) $ nosetests -s -v -w apps これで print文で出力した内容が結果として表示される。 -v と -w とかはググれば出てくるので説明割愛 一緒にXUnit系のXMLも吐き出したい (--with-xunit) $ nosetests --with-xunit -s -v -
An open source load testing tool. Define user behaviour with Python code, and swarm your system with millions of simultaneous users. Tweet Follow @locustio Define user behaviour in code No need for clunky UIs or bloated XML. Just plain code. Distributed & Scalable Locust supports running load tests distributed over multiple machines, and can therefore be used to simulate millions of simultaneous u
書こう、書こうとおもってさぼってた話を書きます。 複数の Python バージョンをサポートするライブラリを作っていると、tox があるとテストがとても楽になります。 ただし、Python のバージョンによって依存するライブラリが変化する場合は、 setup.py と tox.ini の両方にその記述を書く必要があります。 例えば、python2.6 では unittest2 を使い、python2.7 以降では unittest2 を使わない場合は次のようになります。 # setup.py # -*- coding: utf-8 -*- test_requires = ['mock'] if sys.version_info < (2, 7): test_requires.append('unittest2') setup( name='example', extras_require=
単体テストガイドライン¶ Pylons プロジェクトは、このドキュメントの元となった Tres Seaver によって書かれた Avoiding Temptation: Notes on using unittest effectively に倣ったユニットテスト教義をかなり厳格に守っています。 Note このドキュメントは、ほとんど排他的に 単体 テストを扱います。 結合テストまたは機能テストに対しては私たちは特別の教義を持っていません。 しかし、下記の tips の多くはその文脈でも再利用できます。 悪い単体テストを避けるための tips¶ ある人々は “don’t repeat yourself” をむやみに信じてきました (drink the KoolAid): 私たちは、ほとんどの場合にはコードの繰り返しをしないことが 美徳であることに同意します。しかし、単体テストコードはその例
xxxx.pyに直接以下のようにコードを書いているのだと想定します。 import sys arg = sys.argv[1] count = raw_input("count? ") # write some code and set 'result' value print result これは以下のように書けます。 import sys def run(argv, count): # write some code and set result value return result def main(): x = raw_input("count? ") result = run(sys.argv, x) print result if __name__ == '__main__': main() この様に書かれたxxxx.pyには3つのメリットがあります。 直接実行すれば変更前と
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く