✅ Add the docs_src directory to test coverage and update tests#1904
✅ Add the docs_src directory to test coverage and update tests#1904tiangolo merged 14 commits intofastapi:masterfrom
docs_src directory to test coverage and update tests#1904Conversation
Codecov Report
@@ Coverage Diff @@
## master #1904 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 243 390 +147
Lines 7419 9747 +2328
===========================================
+ Hits 7419 9747 +2328
Continue to review full report at Codecov.
|
|
📝 Docs preview for commit a57d719cbfe0cb2d4dcb0afbdaceb46171c12a7c at: https://5f399310ac0d4928ee19262e--fastapi.netlify.app |
|
📝 Docs preview for commit 42e8e73 at: https://5f39a0cb98faa3d93b585386--fastapi.netlify.app |
docs_srcdocs_src
|
📝 Docs preview for commit 5244b0a at: https://5f39aeda46997952ac1355c1--fastapi.netlify.app |
|
📝 Docs preview for commit 44fe4952dce9e3f2b9c614eddc230f464ec1d255 at: https://5fa32afa0b2657112b5b7f05--fastapi.netlify.app |
|
@tiangolo I've rebased it, I'm not sure why the docs stage is failing on the CI, but I saw another PR failing with the same reason. |
|
📝 Docs preview for commit 20df532 at: https://5fb6c9dbfdba270137694c33--fastapi.netlify.app |
|
📝 Docs preview for commit b372943 at: https://605129a909eae400d1973228--fastapi.netlify.app |
Update highlighted lines and consistency with names
simplify the changes, and keep individually testable tests in VS Code
docs_src directory to test coverage and update tests
|
Great, thanks @Kludex! 🚀 ✔️ I updated it a bit, updated the docs where necessary to match the changed examples, and added a couple of missing tests for full coverage. Thanks! 🍰 ☕ |
| test_main_b.test_create_item_bad_token() | ||
| test_main_b.test_read_inexistent_item() | ||
| test_main_b.test_read_item() | ||
| test_main_b.test_read_item_bad_token() |
There was a problem hiding this comment.
This doesn't duplicate the tests as well?
There was a problem hiding this comment.
If I remember correctly, the tests from docs_src are not run by pytest, so the way to run them and have coverage for that is to do this.
Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I'm checking each one in order.
There was a problem hiding this comment.
I remember doing what I did because before my changes the tests were running twice, and I think (I didn't check) this makes them run twice (those were your changes, just for context...), because (I think) the import is enough to make pytest find the tests. Anyway... 👀
There was a problem hiding this comment.
Hum, maybe I have to review this again.
Although, one possible explanation is if you were running pytest and I was running pytest tests.
But anyway, yeah, maybe for later. 😅
…tapi#1904) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
I've just spotted a typo in the test script:
pytest --cov=fastapi --cov=tests --cov=docs/src --cov-report=term-missing --cov-report=xml tests ${@}docs/srcis a typo, we want to coverdocs_src.If you don't trust me
you can check at the end of the test:
I'll be increasing the coverage for those tests on this PR.
Report on the missing coverage:

Changes:
:skip-coveredin the terminal Pytest report. It makes it easy to read missing coverage.--cov=testsfrom test scriptdocs/src->docs_srctestis imported in thetests, there's no need for wrapping it. If you do so, it calls the test function twice.After the fixes:

EDIT:
November 4, 2020: This PR is still useful. And I've added the coverage on the
testsonce again.November 10, 2020: Rebase it, everything is fine!