You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm starting to look into writing tests for the RO-Crate and cat-log merge requests, but I really miss the fixtures in pytest, and also not having to write a class, then methods, etc.
For me one of the biggest wins of using pytest is adding fixtures that can be reused in several other tests. With unitest we can create objects needed for the tests in the setUp function, but then if we have another file with another test that needs something similar (or parts of it) then we have to design some OO way to share that to avoid duplication.For example, see these two different test files.
There is a lot of boilerplate code that is duplicated (I think there are other test files with similar code). With pytest we could have a conftest.py file at the root of the test directory, with something like:
importpytestimportrandomfromautosubmit.experiment.experiment_commonimportbase36encode@ pytest.fixturedefexpid():
"""Autosubmit expid is a base-36 radix value, with at least 4 characters. We first pick a random number between 0 and the last possible number to produce a 4-character expid ``(36 ^ 4) - 1``, so ``1_679_615`` (we do not need to test with len > 4)."""random_int=random.randint(0, 1_679_615)
returnbase36encode(random_int)
@ pytest.fixturedefjob_list(expid, mocker):
as_conf=mocker.Mock()
as_conf.experiment_data=dict()
as_conf.experiment_data["JOBS"] =dict()
as_conf.jobs_data=as_conf.experiment_data["JOBS"]
as_conf.experiment_data["PLATFORMS"] =dict()
returnJobList(expid, FakeBasicConfig, YAMLParserFactory(...), JobListPersistenceDb(...), as_conf)
I'm starting to look into writing tests for the RO-Crate and
cat-log
merge requests, but I really miss the fixtures in pytest, and also not having to write a class, then methods, etc.For me one of the biggest wins of using pytest is adding fixtures that can be reused in several other tests. With unitest we can create objects needed for the tests in the setUp function, but then if we have another file with another test that needs something similar (or parts of it) then we have to design some OO way to share that to avoid duplication.For example, see these two different test files.
There is a lot of boilerplate code that is duplicated (I think there are other test files with similar code). With pytest we could have a conftest.py file at the root of the test directory, with something like:
And I could use it in any test with:
The text was updated successfully, but these errors were encountered: