Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work. Try for free Learn more
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work. Try for free Learn more
libuvのPython実装であるpyuvのPython3対応しているときに、Python2.6/2.7/3.0/3.1/3.2で個別にテストする必要がありました。 各バージョンのPythonを入れるのも割と大変だし、各バージョンごとに確認するのも非常に手間です。 lazyな私にはこんなのやってられません。がおー。めんどくせー。 というわけでいろいろテストツールをいろいろ探していたら、79.pyで @aodag さんにtoxを教えていただきました。 早速使ってみたので、軽くメモを残しておきます。 ドキュメント ↓を読めば大体わかるはず。 Welcome to the tox automation project — tox 1.4.2-1 documentation ざっくり説明すると Pythonライブラリを複数バージョンでテストするツールです。 CI(Jenkinsなど)で使うことも想
pytest で初めてテストを書いてみました。 今度こそ帰るー、py.test を使って初めてテストを書いた、評判通りすごく良い 2012-02-07 19:48:52 via TweetDeck @t2y noseと比べた感想とか聴きたいです。 2012-02-07 19:55:04 via web to @t2y @methane @t2y テストがこけたときまともなレポートをはくのがpy.testのいいところ 2012-02-07 19:56:34 via twicca to @methane nose と比べて、データ駆動テスト *1 *2 の違いが大きかったのでまとめてみます。 準備 以下の素数判定を行うテスト対象関数があるとします。 PRIME = {2: True, 3: True, 4: False, 5: True, 6: False, 7: True} def is_p
mock を使ったニットテストの、シンプルなシーンをまとめました。例として「Twitter アカウントのスクリーンネームを指定し、そのアカウントの最新のツイートの内容を取得する」という機能を実装する場合を考えます。 まず、簡単にユニットテストを書けるような場合から考えます。create_user_timeline_url() 関数を定義し、Twitter アカウントの screen_name を渡すと、そのアカウントのつぶやきを取得するために URL が返される、としましょう。たとえば Twitter アカウントのスクリーンネーム wozozo を渡すと、 http://twitter.com/statuses/user_timeline/wozozo.json が返ってくることを確認します。 実装とテストは以下のようになります。URL のテンプレートを定数にしたほうがいいとかありますが、
テストを書くときに、外部の HTTP API を叩く処理が組み込まれている場合は、何かしらモックが必要です。 どう書くのがスマートなのか良くわからないので色々試してみる 準備するモノ python 2.7.x mock simplejson requests nose covarage テストのデファクト あまりまとまってるのがないので、まとめておきます。 テストランナーは nose または py.test nose はプラグインがステキ py.test はなにやら色々嬉しい事があるらしい モック/スタブは mock テストは unittest (unittest2) カヴァレッジは covarage ? これは良くわからず、基本 Jenkins に食べさせらるタイプで出力できればおk この辺が今のところデファクトでしょうか、ご意見お待ちしております。 mock patch を使うと綺麗に
Claude Code GitHub Actionsを使っていて、自分は以下のような2種類のタスクを依頼することが多い。 実装計画を立ててもらう 実装をしてもらう Claude Codeであれば実装計画はOpusを使って、実装タスクはSonnetを使うみたいな使い分けが簡単にできるのにClaude Code GitHub Actionsではデフォルトだとそれができなかったのでちょっとやってみた。 具体的には、以下のようなclaude.ymlのWorkflowファイルを追加して、GitHub Issueなどのコメントで @claude このタスクの実装計画を Opus で立てて とコメント内にopus, sonnet, haiku のキーワードを含めることで指定したモデルでClaudeが動くようになる。 やっていることは単純で、メッセージ内にopusなどのキーワードをgrepで引っ掛けてmo
unittest — Unit testing framework¶ Source code: Lib/unittest/__init__.py (If you are already familiar with the basic concepts of testing, you might want to skip to the list of assert methods.) The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks in other languages. It supports test automation, sharing of setup and shutdown c
Source code: Lib/unittest/mock.py unittest.mock is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used. unittest.mock provides a core Mock class removing the need to create a host of stubs throughout your test suite. After performing an action, you can make assertions about which methods / att
at·test /əˈtɛst/ To affirm to be correct, true, or genuine. Attest is a test automation framework for Python emphasising modern idioms and conventions. from attest import Tests math = Tests() @math.test def arithmetics(): """Ensure that the laws of physics are in check.""" assert 1 + 1 == 2 if __name__ == '__main__': math.run() Features¶ Collect tests using decorators instead of matching names aga
Flash製アプリの試験用のアクセスパターンを作りたくて gevent を使って簡単なproxy serverを作った。 localhostの8000版で立ち上がるので、FoxyProxy などで、特定のドメインに対する proxy として登録してやると、リクエストを再現するのに必要なデータをmsgpackフォーマットで保存していく。 from gevent.pywsgi import WSGIServer from gevent import monkey from msgpack import packs import httplib def handler(environ, start_response): host = environ['HTTP_HOST'] method = environ['REQUEST_METHOD'] body = environ['wsgi.input
Coverage.py Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not. Coverage measurement is typically used to gauge the effectiveness of tests. It can show which parts of your code are being exercised by tests, and which ar
はじめに nose の組み込みプラグインを利用するとテストで実行された時のカバレッジを取得できます。 テスト実行時のカバレッジを取得できるので、テストでカバーできていない範囲など確認できます。 カバレッジを取得する nose と python-coverage がインストールされている必要があります。 nosetests コマンド実行時に、 --with-coverage オプションを付けることでカバレッジを取得できます。 --cover-tests を付与すると実行されたテスト用コードのカバレッジを取得できます。 インストール手順 $ easy_install -ZU nose $ easy_install -ZU coveragenose からのカバレッジ取得し、HTMLに変換する。 $ cd myproject $ nosetests -v --with-coverage tests
$ python coverage-2.80/coverage.py -e $ python coverage-2.80/coverage.py -x testSuiteCalc.py test0Tasu5 (__main__.testCalc) ... ok test0Hiku5 (__main__.testCalc) ... ok test10Kakeru2 (__main__.testCalc) ... ok test10Waru2 (__main__.testCalc) ... ok ---------------------------------------------------------------------- Ran 4 tests in 0.002s OK $ python coverage-2.80/coverage.py -r -m Calc.py Name S
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く