Use Docker to easily test the sendgrid-python library.
This Docker image contains:
- Python 3.6
- A running instance of Stoplight.io's Prism, which lets you try out the SendGrid API without actually sending email
- A mirrored copy of sendgrid-php so that you may develop locally and then run the tests within the Docker container.
- Clone the sendgrid-python repo
git clone https://github.com/sendgrid/sendgrid-python.gitcd sendgrid-pythonpython setup.py install
- Install Docker
- Setup local environment variable SENDGRID_API_KEY
- Build a Docker image, run Docker container, login to the Docker container
docker image build --tag="sendgrid/python3.6" ./docker-testdocker run -itd --name="sendgrid_python3.6" -v $(pwd):/root/sendgrid-python sendgrid/python3.6 /bin/bash
- Run the tests within the Docker container
sudo docker exec -it sendgrid_python3.6 /bin/bash -c 'cd sendgrid-python; python3.6 -m unittest discover -v; exec "${SHELL:-sh}"'
Now you can continue development locally, and run python3.6 -m unittest discover -v inside of the container to test.
To clean up the container: docker stop sendgrid_python3.6 && docker rm sendgrid_python3.6.
Happy Hacking!
- After step 5 in the QuickStart, within the Docker container:
cd ../python sendmail.py
- Develop per usual locally, but before pushing up to GitHub, you can run the tests locally in the Docker container per step 5 of the quickstart.
- To run all the tests:
python3.6 -m unittest discover -v - To run an individual test:
python3.6 -m unittest [Filename].[Class].[TestName]