Move old API test code into pytest framework#327
Move old API test code into pytest framework#327sveinse merged 5 commits intocustom-components:masterfrom
Conversation
but disable it on Github actions since it requires login credentials.
0ed8197 to
628461c
Compare
tests/zaptec/test_diagnostics.py
Outdated
|
|
||
| # Set manually, or when running 'scripts/test --skip-api' | ||
| SKIP_API_TEST = os.getenv("SKIP_ZAPTEC_API_TEST") == "true" | ||
|
|
There was a problem hiding this comment.
It would be better to move them to conftest.py and make a proper mark. This is probably useful to several test function.
There was a problem hiding this comment.
Could you please clarify what you mean by "proper mark"? I'm probably too tired right now, but I just couldn't get fixtures and mark to behave like I wanted them to. Will take another look at it over the weekend.
There was a problem hiding this comment.
A good nights sleep and some sparring with ChatGPT worked wonders, please have a look at the updated version
There was a problem hiding this comment.
I think that solution is ok. As you've probably seen already, I posted a proposal to how to do it by the use of additional command line parameters. You can chose which to use. In pytest there isn't a right way and a wrong way, just alternative ways to do it.
There was a problem hiding this comment.
Considering how limited our testing still is, I think I prefer to have the API-login-dependent tests run by default and then make exceptions where they don't run. Once we have higher test coverage and the ability to mock out stuff requiring login, we can reconsider to only run these full tests when adding additional arguments.
|
This is how # conftest.py
def pytest_addoption(parser):
parser.addoption(
"--additional", action="store_true", default=False, help="Run additional Zaptec tests"
)
def pytest_collection_modifyitems(config, items):
skip_additional = None
if not config.getoption("--additional"):
skip_additional = pytest.mark.skip(reason="Skip test when --additional isn't used")
for item in items:
if skip_additional is not None and "additional" in item.keywords:
item.add_marker(skip_additional)This can now be used with mark in tests: @pytest.mark.additional
def test_some_function():
....This results in a new command line option |
sveinse
left a comment
There was a problem hiding this comment.
I don't see any more objections. Approved.
but disable it on Github actions since it requires login credentials.