Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FastAPI tests to Pydantic's CI tests #1075

Merged
merged 14 commits into from
Dec 5, 2019

Conversation

tiangolo
Copy link
Collaborator

@tiangolo tiangolo commented Dec 4, 2019

Change Summary

Add FastAPI testing during Pydantic's CI tests.

It has a new Make target test-fastapi.

That, in turn, runs a script test-fastapi.sh.

The script will:

  • Clones FastAPI
  • Get the latest tag (the latest release)
  • Install it in the current environment
  • Install Pydantic from the source
  • Run FastAPI tests

I had to do it in an external Bash script after failing to do it inline in the Makefile. I couldn't find a way to create the variables latest_tag_commit and latest_tag to re-use them in the same Make target.

Related issue number

#1041

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Dec 4, 2019

Codecov Report

Merging #1075 into master will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff           @@
##           master   #1075   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          20      20           
  Lines        3365    3365           
  Branches      663     663           
======================================
  Hits         3365    3365

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 890589a...7435b81. Read the comment docs.

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome.

Much simpler than I expected it to be, just a few small things.

.travis.yml Outdated
@@ -82,6 +82,7 @@ jobs:
script:
- pip uninstall -y cython email-validator typing-extensions devtools
- make test
- make test-fastapi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fastapi tests should be be an entirely new stage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. This should be corrected in the latest.

test-fastapi.sh Outdated
@@ -0,0 +1,24 @@
#! /usr/bin/env bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're brave you could probably implement this inside the Makefile.

Makefile even has it's own logic for checking if a file or directory exists.

If it's a pain, leave it for now and I'll fix in future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise maybe move this into tests to avoid cluttering up the root directory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make the fastapi directory and any other related files should also live in tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About putting it in the Makefile, I tried first to put all the bash script in it, but I couldn't.

I tried several things, but I couldn't get the inline variables to work, the: latest_tag_commit and latest_tag. I also tried getting rid of them and "sub-bashing" the commands, nesting them, but couldn't get that to work either 😞

If you know a Make trick for that, let me know 😅

About the logic to check for the directory, I first had a:

fastapi:
	git clone https://github.com/tiangolo/fastapi.git

.PHONY: test-fastapi
test-fastapi: fastapi
	bash tests/test-fastapi.sh

To use the automatic directory target fastapi. But I removed it and put it all in the bash script, trying not to clutter the Makefile.

If you prefer it like that, with the git clone in the Makefile, I can put it there.

The rest of the Bash script... I don't really know what else to try to make those variables to work 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you would probably prefer the extra Make target, so I just went ahead and refactored that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the script to ./tests/.

But I couldn't move the fastapi repo clone to under tests, because tests is already a package, and it seems the imports get confused when trying to run tests inside of a directory inside of a tests directory.

I can also clone it to a ./tmp/fastapi dir to make it explicit. Or a ./.tmp/fastapi to make it a hidden dir.

test-fastapi.sh Outdated
git checkout "${latest_tag}"
pip install flit
flit install
SKIP_CYTHON=1 pip install -e ..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this can be achieved by changing the recipe to require install as a parent-recipe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it wouldn't work, but it it did! 🎉

test-fastapi.sh Outdated Show resolved Hide resolved
test-fastapi.sh Outdated Show resolved Hide resolved
@samuelcolvin samuelcolvin merged commit ea709cc into pydantic:master Dec 5, 2019
@tiangolo tiangolo deleted the fastapi-ci branch December 5, 2019 13:06
@tiangolo
Copy link
Collaborator Author

tiangolo commented Dec 5, 2019

Thanks! 🚀 🎉

andreshndz pushed a commit to cuenca-mx/pydantic that referenced this pull request Jan 17, 2020
fix pydantic#1041

* Add test-fastapi.sh script, after failing to create reusable variables in Make

* Add test-fastapi Make target

* Add fastapi dir for tests to gitignore

* Add fastapi tests to Travis

* Update test-fastapi to run the minimum (pytest)

* Move make test-fastapi to normal run, no "Without Deps"

* Install Pydantic without Cython for FastAPI tests

* Put FastAPI tests in its own Travis job

* Add PR changes description

* Remove coverage for FastAPI, it's not relevant for Pydantic

* Implement code review changes, refactor Makefile use and fastapi tests

* Add a bug intentionally, to test that FastAPI tests are using the current source

and make sure it actually breaks CI.

* Fix intentional bug. Confirmed it breaks Travis for FastAPI.
alexdrydew pushed a commit to alexdrydew/pydantic that referenced this pull request Dec 23, 2023
…ydantic#1075)

Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants