diff --git a/docs/fr/docs/advanced/async-tests.md b/docs/fr/docs/advanced/async-tests.md index a528c80fe..6dbc54701 100644 --- a/docs/fr/docs/advanced/async-tests.md +++ b/docs/fr/docs/advanced/async-tests.md @@ -1,26 +1,26 @@ -# Async Tests +# Tests Asynchrones -You have already seen how to test your **FastAPI** applications using the provided `TestClient`. Up to now, you have only seen how to write synchronous tests, without using `async` functions. +Vous avez déjà vu comment tester vos applications **FastAPI** en utilisant le `TestClient` fourni. Jusqu'à présent, vous avez seulement vu comment écrire des tests synchrones, sans utiliser des fonctions `async`. -Being able to use asynchronous functions in your tests could be useful, for example, when you're querying your database asynchronously. Imagine you want to test sending requests to your FastAPI application and then verify that your backend successfully wrote the correct data in the database, while using an async database library. +Être capable d'utiliser des fonctions asynchrones dans vos tests peut être utile, par exemple, lorsque vous requêtez de manière asynchrone votre base de données. Imaginez que vous vouliez tester l'envoi de requête à votre application FastAPI, puis vérifier que votre backend a bien écrit la bonne donnée dans la base de données, tout en utilisant une librairie de base de données asynchrone. -Let's look at how we can make that work. +Voyons comment faire. ## pytest.mark.anyio -If we want to call asynchronous functions in our tests, our test functions have to be asynchronous. AnyIO provides a neat plugin for this, that allows us to specify that some test functions are to be called asynchronously. +Afin de permettre l'appel de fonctions asynchrones dans nos tests, il est essentiel que nos fonctions de tests soient asynchrones. AnyIO propose un plugin soigneusement conçu pour cela, qui nous permet de spécifier que certaines fonctions de test doivent être appelées de manière asynchrone. ## HTTPX -Even if your **FastAPI** application uses normal `def` functions instead of `async def`, it is still an `async` application underneath. +Même si votre application **FastAPI** utilise des fonctions `def` normales plutôt que des `async def`, elle reste une application `async` application en dessous. -The `TestClient` does some magic inside to call the asynchronous FastAPI application in your normal `def` test functions, using standard pytest. But that magic doesn't work anymore when we're using it inside asynchronous functions. By running our tests asynchronously, we can no longer use the `TestClient` inside our test functions. +`TestClient` utilise de la magie à l'intérieur pour appeler l'application FastAPI dans vos fonctions de test `def` normales, en utilisant un standard pytest. Mais cette magie ne marche plus lorsque vous l'utilisez dans une fonction asynchrone. En lançant nos tests de manière asynchrone, `TestClient` ne peut plus être utilisé dans nos fonctions de tests. -The `TestClient` is based on HTTPX, and luckily, we can use it directly to test the API. +`TestClient` repose HTTPX, et par chance, on peut l'utiliser directement pour tester l'API. -## Example +## Exemple -For a simple example, let's consider a file structure similar to the one described in [Bigger Applications](../tutorial/bigger-applications.md){.internal-link target=_blank} and [Testing](../tutorial/testing.md){.internal-link target=_blank}: +Prenons un exemple simple, on considère une structure de fichier similaire à celle décrite dans [Applications plus grandes](../tutorial/bigger-applications.md){.internal-link target=_blank} et [Testing](../tutorial/testing.md){.internal-link target=_blank}: ``` . @@ -30,21 +30,21 @@ For a simple example, let's consider a file structure similar to the one describ │ └── test_main.py ``` -The file `main.py` would have: +Dans le fichier `main.py` il y aurait: ```Python {!../../../docs_src/async_tests/main.py!} ``` -The file `test_main.py` would have the tests for `main.py`, it could look like this now: +Le fichier `test_main.py` contiendrait les tests pour `main.py`, et pourrait désormais ressembler à : ```Python {!../../../docs_src/async_tests/test_main.py!} ``` -## Run it +## Lancez les -You can run your tests as usual via: +Comme d'habitude, vous pouvez lancer vos tests en utilisant :