Improve testing harness to allow tests on real devices (#197)

* test_cli: provide return values to patched objects to avoid warning about non-awaited calls

* test_cli: restore alias after testing

* smartstrip: remove internal update() calls for turn_{on,off}, set_led

* Make sure power is always a float

* Fix discovery tests

* Make tests runnable on real devices

* Add a note about running tests on a real device

* test_strip: run update against the parent device
This commit is contained in:
Teemu R
2021-09-19 23:45:48 +02:00
committed by GitHub
parent b088596205
commit 1803a83ae6
14 changed files with 70 additions and 24 deletions

View File

@@ -147,7 +147,7 @@ def get_device_for_file(file):
with open(p) as f:
sysinfo = json.load(f)
model = basename(file)
p = device_for_file(model)(host="123.123.123.123")
p = device_for_file(model)(host="127.0.0.123")
p.protocol = FakeTransportProtocol(sysinfo)
asyncio.run(p.update())
return p
@@ -168,21 +168,29 @@ def dev(request):
asyncio.run(d.update())
if d.model in file:
return d
raise Exception("Unable to find type for %s" % ip)
else:
pytest.skip(f"skipping file {file}")
return get_device_for_file(file)
def pytest_addoption(parser):
parser.addoption("--ip", action="store", default=None, help="run against device")
parser.addoption(
"--ip", action="store", default=None, help="run against device on given ip"
)
def pytest_collection_modifyitems(config, items):
if not config.getoption("--ip"):
print("Testing against fixtures.")
return
else:
print("Running against ip %s" % config.getoption("--ip"))
requires_dummy = pytest.mark.skip(
reason="test requires to be run against dummy data"
)
for item in items:
if "requires_dummy" in item.keywords:
item.add_marker(requires_dummy)
# allow mocks to be awaited