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
This guide explains how to organize and execute integration tests for your project using Pytest. The primary goal is to enhance test maintainability by following a clear structure and adhering to naming conventions.
Organization of Test Modules
To ensure a close correspondence between the implementation modules' hierarchy and the test modules, follow these guidelines:
Integration tests for the AntaREST application reside in the tests/integration directory.
This directory contains assets used for tests (resources such as studies, application configuration for testing, etc.) and fixtures1 used for dependency injection in your tests.
Within this package, create a sub-module named after the tested component. For example, if the component is "watcher," name this sub-module test_watcher.
Naming Test Functions
For each component you test that involves multiple endpoints2, name test functions as follows:
For the "watcher" component, suppose there is an endpoint /watcher/_scan implemented by a function named scan_dir in the antarest.study.web.watcher_blueprint module. In this case, name your test function test_scan_dir.
If you have multiple test scenarios for the same endpoint, add a descriptive suffix to the test function, for example, test_scan_dir__scenario1, test_scan_dir__scenario2, etc.
Using Fixtures
In your test module, use fixtures defined in the conftest.py file in the tests/integration package. For instance, you can use the user_access_token fixture (access token for the "admin" user's API) and the study_id fixture (ID of the "STA-mini" study used as a working base for tests).
Limiting the Number of Test Functions
Since integration tests can be time-consuming due to initial setup (app fixture), it is recommended to limit the number of test functions per endpoint. For some components, you may consider grouping multiple aspects into a single test, such as test_lifecycle, which covers the entire component lifecycle (creation, update, deletion, error handling).
Footnotes
A fixture in Pytest is a Python function used to set up a specific test environment and provide data or objects necessary for running tests. ↩
An endpoint is a URL associated with an HTTP method, used to access specific functionalities of a web application. For instance, the POST /watcher/_scan endpoint allows creating a workspace analysis task in Antares Web. ↩
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Integration Testing Guide with Pytest
This guide explains how to organize and execute integration tests for your project using Pytest. The primary goal is to enhance test maintainability by following a clear structure and adhering to naming conventions.
Organization of Test Modules
To ensure a close correspondence between the implementation modules' hierarchy and the test modules, follow these guidelines:
Integration tests for the AntaREST application reside in the
tests/integration
directory.This directory contains assets used for tests (resources such as studies, application configuration for testing, etc.) and fixtures1 used for dependency injection in your tests.
Within this package, create a sub-module named after the tested component. For example, if the component is "watcher," name this sub-module
test_watcher
.Naming Test Functions
For each component you test that involves multiple endpoints2, name test functions as follows:
For the "watcher" component, suppose there is an endpoint
/watcher/_scan
implemented by a function namedscan_dir
in theantarest.study.web.watcher_blueprint
module. In this case, name your test functiontest_scan_dir
.If you have multiple test scenarios for the same endpoint, add a descriptive suffix to the test function, for example,
test_scan_dir__scenario1
,test_scan_dir__scenario2
, etc.Using Fixtures
In your test module, use fixtures defined in the
conftest.py
file in thetests/integration
package. For instance, you can use theuser_access_token
fixture (access token for the "admin" user's API) and thestudy_id
fixture (ID of the "STA-mini" study used as a working base for tests).Limiting the Number of Test Functions
Since integration tests can be time-consuming due to initial setup (
app
fixture), it is recommended to limit the number of test functions per endpoint. For some components, you may consider grouping multiple aspects into a single test, such astest_lifecycle
, which covers the entire component lifecycle (creation, update, deletion, error handling).Footnotes
A fixture in Pytest is a Python function used to set up a specific test environment and provide data or objects necessary for running tests. ↩
An endpoint is a URL associated with an HTTP method, used to access specific functionalities of a web application. For instance, the POST /watcher/_scan endpoint allows creating a workspace analysis task in Antares Web. ↩
Beta Was this translation helpful? Give feedback.
All reactions