Skip to content

Instantly share code, notes, and snippets.

@geryxyz
Created February 7, 2022 08:06
Show Gist options
  • Save geryxyz/ab1eaa43b5952575f07e29a7ca5b6c52 to your computer and use it in GitHub Desktop.
Save geryxyz/ab1eaa43b5952575f07e29a7ca5b6c52 to your computer and use it in GitHub Desktop.
Hinting system skeleton/proof of concept/demo for pytest
import pytest
import typing
# add more hint properties as you wish...
def hint(id: str, name: typing.Optional[str] = None):
def _hint(fn: typing.Callable):
fn.hint_id = id
fn.hint_name = name if name is not None else id
return fn
return _hint
def record_hint_properties(record_property, hinting_fn: typing.Callable):
if '_' in hinting_fn.hint_id:
raise Exception('_ are not allowed in id')
record_property(f'{hinting_fn.hint_id}_hintname', hinting_fn.hint_name)
@hint(id='awesome', name="A Very Awesome Hint")
@pytest.fixture
def awesome_hint(record_property):
record_hint_properties(record_property, awesome_hint)
def test_foo(awesome_hint):
assert True
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite name="pytest" errors="0" failures="0" skipped="0" tests="1" time="0.019"
timestamp="2022-02-07T09:03:36.689404" hostname="DESKTOP-KJ6HLT9">
<testcase classname="main" name="test_foo" time="0.001">
<properties>
<property name="awesome_hintname" value="A Very Awesome Hint"/>
</properties>
</testcase>
</testsuite>
</testsuites>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment