Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

AssertionError when running with_plugs.py example

オープン
#925 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
testing-qa

調査の方向性

まず with_plugs.py の例を実行し、80 行目付近の測定宣言を確認します。openhtf/util/validators.py の equals バリデータが受け取る前に、そのフェーズ引数がどのように処理されるかを追跡します。expected_retcode 引数がその整数値に置き換えられ、例が AssertionError なしで実行されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

When running the with_plugs.py example. the following output is generated:

$ python3 with_plugs.py
Traceback (most recent call last):
  File "with_plugs.py", line 80, in <module>
    htf.Measurement('retcode').equals('{expected_retcode}', type=int)
  File "/usr/lib/python3.8/site-packages/openhtf/core/measurements.py", line 257, in _with_validator
    validators.create_validator(attr, *args, **kwargs))
  File "/usr/lib/python3.8/site-packages/openhtf/util/validators.py", line 80, in create_validator
    return _VALIDATORS[name](*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/openhtf/util/validators.py", line 175, in equals
    assert type is None or issubclass(type, six.string_types), (
AssertionError: Cannot use a non-string type when matching a string

I believe this is being caused by the {expected_retcode} argument to the validator in the measurement not actually being substituted for the argument, so the validator sees its value argument as a string containing {expected_retcode} instead of an integer containing the value passed to the test.

# Note: phase name and total_time measurement use {} formatting with args
# passed into the phase so each phase has a unique name.
@htf.PhaseOptions(name='Ping-{pinger.host}-{count}')
@htf.plug(pinger=PingPlug.placeholder)
@htf.measures(
    'total_time_{pinger.host}_{count}',
    htf.Measurement('retcode').equals('{expected_retcode}', type=int)
)

I replaced the standard equals validator with this one:

class MyEquals(ValidatorBase):
  def __init__(self, value, type=None):
    self.value = value
    self.type = type

  def __call__(self, value):
    print("type(value)) = " + str(type(value)))
    print("self.type = " + str(self.type))
    print("value = " + str(value))
    print("self.value = " + str(self.value))
    return type(value) == self.type and value == self.value

And this is the output I receive from the validator:

type(value)) = <class 'int'>
self.type = <class 'int'>
value = 0
self.value = {expected_retcode}
主要言語
Python
スター
723
フォーク
239
平均マージ
3時間 17分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/openhtf のほかの issue

google/openhtf の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。