AssertionError when running with_plugs.py example
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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/openhtf
-
PERCENT double declarationPossibly taken @Sanjays2402 claimed this 79 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 60/100
google/openhtf#1250 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 4/5 3-5 days Newbie friendliness 25/100
google/openhtf#1219 · 3 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
Status: Triage Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Objects.List treats versions=false (and similar flags) as truePossibly taken @andaaron claimed this today. Openpriority: p2 type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
googleapis/storage-testbench#829 ·
Maintainers usually reply within 2 days
-
[Bug]: memory provider treats 1:1 DMs as shared surfaces, so DM turns never receive reviewed recordsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
rlaope/oh-my-hermes#2088 ·
Maintainers usually reply within 1 day