問題タブ [pytest]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
django - py.test -n と Django TestCase の URL
Django テストで特定の url-config を使用するには、それを指定するだけです:
ただし、実装がスレッドセーフであるようには見えません。
そして、テスト スイートを py.test -n8 (8 つの CPU すべてを使用) で実行した後、テスト ログに 404 エラーが表示されます。
他の誰かがこの問題を見たり解決したりしましたか?
python - py.test: KeyboardInterrupt を取得してティアダウンを呼び出す
私は py.test を使用していくつかのテストを作成しており、テストでは funcargs を使用しています。これらのファンカーグには、次のように conftest.py で定義された独自のセットアップとティアダウンがあります。
conftest.py:
私の問題は、誰かが CTRL+C を使用してテストの実行を停止すると、すべてが未処理のままになることです。フック pytest_keyboard_interrupt があることは知っていますが、そこから何をすべきかわかりません。
初心者の質問で申し訳ありません。
python - py.test で、xfail としてマークされたテストを明示的にスキップした場合、「xfailed」ではなく「スキップ」と報告するにはどうすればよいですか?
xfail としてマークされた py.test テスト関数があります。
私の pytest_runtest_setup() フックでは、このテストを明示的にスキップします。
py.test を実行すると、テストが失敗したことが報告されます。
このテストがスキップされたと報告するように py.test を取得するにはどうすればよいですか?
「pytest_runtest_setup() フックでこのテストから xfail マーキングを削除するにはどうすればよいですか?」と尋ねているようです。
ありがとう。
python - 特定のディレクトリをスキップするようにpy.testに指示するにはどうすればよいですか?
setup.cfg内のオプションを使用してnorecursedirs
、特定のディレクトリからテストを収集しないようにpy.testに指示しようとしましたが、無視されているようです。
実行するpy.test
と、内部からテストがどのように取得されるかがわかりますlib/third
。
pytest - pytest - setup_module 内で funcargs を使用する
conftetst.py に独自のコマンド ライン オプションを含めます。
と
モジュール内の通常の関数内でこのコマンド ライン オプションを使用すると、次のようになります。
期待どおりに動作します。
ここで、setup_module 関数を含めて、いくつかのテストの前にいくつかのものを作成/コピーしたいと思います。
残念ながら、setup_module 関数内でこのコマンド ライン オプションにアクセスする方法がわかりました。私が試したことは何も機能しません。
助けてくれてありがとう、提案。
乾杯
pytest - funcargs 関数をデバッグするにはどうすればよいですか?
funcargs 関数内で pdb にドロップするにはどうすればよいですか? また、funcargs 関数で print ステートメントからの出力を確認するにはどうすればよいですか?
私の元の質問には次のものが含まれていましたが、単に間違った funcarg をインストルメント化していたことが判明しました。はぁ。
私は試した:
-s の有無にかかわらず呼び出します。
私は試した:
と:
と:
何も出力を生成しなかったか、テストの失敗を引き起こしました。
python - Python: best way to test a single method of a class
I have a class like the following:
As you can see, initializing the class needs to feed in arg1, arg2, and arg3. However, testing func1 and func2 does not directly require such inputs, but rather, it's simply an input/output logic.
In my test, I can of course instantiate and initialize a test object in the regular way, and then test func1 and func2 individually. But the initialization requires input of arg1 arg2, arg3, which is really not relevant to test func1 and func2.
Therefore, I want to test func1 and func2 individually, without first calling __init__
. So I have the following 2 questions:
- What's the best way of designing such tests? (perferably, in py.test)
- I want to test func1 and func2 without invoking
__init__
. I read from here thatA.__new__()
can skip invoking__init__
but still having the class instantiated. Is there a better way to achieve what I need without doing this?
NOTE:
There have been 2 questions regarding my ask here:
- Is it necessary to test individual member functions?
- (for testing purpose) Is it necessary to instantiating a class without initializing the object with
__init__
?
For question 1, I did a quick google search and find some relevant study or discussion on this:
- Unit Testing Non Public Member Functions
- (PDF) Incremental Testing of Object-Oriented Class Structures.
We initially test base classes having no parents by designing a test suite that tests each member function individually and also tests the interactions among member functions.
For question 2, I'm not sure. But I think it is necessary, as shown in the sample code, func1 and func2 are called in __init__
. I feel more comfortable testing them on an class A object that hasn't been called with __init__
(and therefore no previous calls to func1 and func2).
Of course, one could just instantiate a class A object with regular means (testobj = A()) and then perform individual test on func1 and func2. But is it good:)? I'm just discussing here as what's the best way to test such scenario, what's the pros and cons.
On the other hand, one might also argue that from design perspective one should NOT put calls to func1 and func2 in __init__
in the first place. Is this a reasonable design option?
pytest - py.testで、xfailマークの範囲を狭めるにはどうすればよいですか?
pytestxfailマークの範囲を狭めたいと思います。私が現在使用しているので、それはテスト機能全体をマークし、機能の失敗はクールです。
おそらく「withpytest.raises(module.Error)」のようなコンテキストマネージャを使用して、それをより小さなスコープに絞り込みたいと思います。例えば:
私が呼び出す3つのメソッドのいずれかでアサートすると、このテストはxfailになります。代わりに、second_step()でアサートされ、他の場所ではアサートされない場合にのみ、テストをxfailにしたいと思います。このようなもの:
これはpy.testで可能ですか?
ありがとう。
pytest - py.test とティアダウン
ネットワーク化されたハードウェア デバイスに接続し、設定などを変更する py.test でテスト スイートを開発しています。各テスト メソッドは、設定の組み合わせを変更し、結果をアサートします。テストごとにすべてのデバイス設定をリセットせずに、テスト固有のティアダウンを行うにはどうすればよいですか?
python - HTML レポートを作成しています。ローカル ファイルへの編集リンクを作成できますか?
次のような py.test レポートを変換したいと思います。
理解してナビゲートしやすいものにします(そしてできれば簡単に生成できます)。スタック フレームの展開/折りたたみ、最小限の構文の強調表示、「定義に移動」リンクを追加したいと考えています。ファイルへのパスを、.py の既定のエディターでファイルを開くリンクに変換できることを願っています。ファイル。
ローカル ファイルへのリンクを作成するための解決策を Google で検索して、ローカル エディターで開くことを試みましたが、見つかったのは Web サーバーに関する回答だけでした。ユーザーがレポートをダブルクリックしてレポートを開くため、セキュリティ上の問題はありません..?
おそらく、html以外のものを使用する必要がありますか?