0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCode でリモートの pytest のテストコードを実行

Posted at

やりたいこと

Windows の VSCode から Linux 上の django のアプリケーションの pytest のテストコードをデバッグする。

VSCode の設定

VSCode でリモートの Linux に接続

Visual Studio Code で Linux server 上のファイルを編集 を参考に Windows から Linux サーバに接続する。

VSCode に python の debugger extension をインストール

VSCode で python debugger の install in SSH をクリックしてインストールする。
インストールすると、左メニューに debug のアイコンが追加される

テストの設定

"Configure Python Tests" をクリック
"pytest pytest framework" をクリック
Select the directory containig the tests で ". Root directory" を選択

テストコードの実行

ファイル構成

pytest による django の Web API のテスト自動化」と同じファイル構成で pytest のテストコードを実行する。

pytest1
├── app1
│   └── test_apis
│        ├── __init__.py
│        ├── test_api_create.py
│        └── test_api_list.py
├── conftest.py
└── pytest.ini

django のプロジェクトをオープン

左メニューのファイルエクスプローラで上記の pytest1 ディレクトリをオープンする。

テストの実行

単純にテストを実行するには以下のアイコンをクリックする。
test_exec_icon.png

ブレークポイントの設定

プログラムの行番号の左ををクリックすると、でブレークポイントを設定できる。
break_point.png

以下のアイコンをクリックしてテストコードを実行すると、ブレークポイントでプログラムが停止し、変数の値などが表示される。
debug_exec_icon.png

vscode_breakpoint.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?