Migrating tests to the new fixtures¶
Many codebases still rely on old fixtures, primarily due to their inclusion in lime-project templates. However, these fixtures significantly degrade the performance of testing suites compared to the newer ones. It's recommended that whenever a project with old fixtures is encountered, the test files should be rewritten to use the new ones. Here is a short guide on how to act when working on refactoring the test files.
- Find the
conftest.pyfile and look if old fixtures are used. - Replace the
limetypesfixture with code below (if you use something else than custom_dsl.dsl, use what you had before).
@pytest.fixture(scope="session")
def lime_types():
return lime_type.create_limetypes_from_dsl(custom_dsl.dsl)
- Remove the
limeappfixture in order to use the framework'slime_app. - Remove the
databasefixture (the framework's fixture of the same name will be used automatically). - Replace all occurrences of
limeappwithlime_app. - Replace all occurrences of
webapptoweb_client(exclude the changes which may accidentally be done topoetry.lock). - Run all tests and make adjustments if anything breaks.
Tips and tricks¶
Endpoint tests gives an error when no coworker is set for app¶
This is caused because in the DSL, the coworker does not have a label user, which makes it impossible to read the
attribute lime_app.coworker. The DSL file should be modified with the proper user label set.
If the problem still exists, it may be because the limepkg-dsl-extract overrides the label property. The fix for
that is currently in progress and the documentation will be updated after the proper release.
Adding a specific type of user to app.user¶
If you need a lime_app with specific app.user for some reason, maybe special functionality for a portaluser you can
create a separate lime_app instance for that matter.
You can achieve that by using lime_test.app_create_app and passing the created user as active_user argument.
Example:
import lime_test
@pytest.fixture
def lime_app_portal_user(database, lime_types, create_user, monkeypatch):
user: LimeUser = create_user(
username="apiuser_portal@lime.tech",
password="password",
full_name="Portal User",
_return_entity=True
)
app = lime_test.app.create_app(
monkeypatch=monkeypatch,
database=database,
limetypes=lime_types,
active_user=user,
)
return app
The tests take a long time to run¶
This may happen due to a bug in lime-crm tests. This bug is solved now, upgrade to minimum 2.936.2 CRM version to solve it.
Related pages¶
- Fixtures is the reference for the new fixtures.
- Running tests explains where tests live and how to run them.