Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

AssertionError when running with_plugs.py example

Open
#925 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
testing-qa

Research direction

Start by running the with_plugs.py example and inspect the measurement declaration around line 80. Trace how its phase arguments are handled before the equals validator in openhtf/util/validators.py receives them. Done means the expected_retcode argument is substituted with its integer value and the example runs without the AssertionError.

Written by the indexing model from the issue text.

Description

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}
Dominant language
Python
Stars
723
Forks
239
Avg merge
3h 17m
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/openhtf

All issues in google/openhtf

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.