LoginSignup
1
2

More than 5 years have passed since last update.

[python] 指定ページの表示速度を計測、そしてレポートをまとめる

Last updated at Posted at 2018-08-25

ページの表示速度をrequests を使って

python のバージョンは3.6.5 です。

# -*- coding: utf-8 -*-
import requests

def test1():
    print ("この記事")
    r = requests.get('https://qiita.com/sasajidegozaimath/items/e4e401b3de41360376c2') 

    # elapsed を用いて以下の通り計測します。
    print (r.elapsed.total_seconds())

    # 404の場合はテストがFailuredであることを確認するために、assertion を入れます
    assert '200' in str(r.status_code)

実行には pytest--html → https://pypi.org/project/pytest-html/ のコマンドを用います。
インストールしていない場合はインストールしておくとレポートの作成が捗ると思います。


pytest ***.py --html=report.html

report の箇所は、好きなファイル名にしてください。
結果ファイルは以下のようにhtml形式で出力されます。
成功・失敗がひとめでわかるので嬉しいです。
20180825.png

1
2
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
1
2