Development environment for the Python requests package

szabgab

Gabor Szabo

Posted on March 11, 2023

Development environment for the Python requests package

To make it easier to start to contribute to an open source project, one needs to know how to set up a development environment locally and how to run the tests of the project locally.

As I did not find this information for the requests Python library I am now trying to describe it myself.

Clone the repository

This part can be found in the README of the GitHub repository.

You need to have Python installed and some libraries. You can run it natively on your operating system in a virtual environment or you can run it in a Docker container.

Start Docker

docker run -it --rm --workdir /opt -v$(pwd):/opt python:3.11 bash
Enter fullscreen mode Exit fullscreen mode
make init
Enter fullscreen mode Exit fullscreen mode

That basically runs

pip install -r requirements-dev.txt
Enter fullscreen mode Exit fullscreen mode

To run the tests you could type

make test
Enter fullscreen mode Exit fullscreen mode

but it needs tox so first you'll have to run

pip install tox
Enter fullscreen mode Exit fullscreen mode

then you can run

make test
Enter fullscreen mode Exit fullscreen mode

That will actually run

tox -p
Enter fullscreen mode Exit fullscreen mode

I also like to be able to run the tests and generate code-coverage report and run the tests in random order.

pip install pytest-random-order pytest-coverage

pytest -svv --random-order --cov-config .coveragerc --cov=requests --cov-report html --cov-report term --cov-branch
Enter fullscreen mode Exit fullscreen mode

Virtualenv

virtualenv -p python3 venv
. venv/bin/activate
Enter fullscreen mode Exit fullscreen mode
pip install pytest-coverage
pytest --cov-config .coveragerc --verbose --cov-report term --cov-report xml --cov-report html --cov=requests --cov-branch tests
Enter fullscreen mode Exit fullscreen mode

Adding this to the project

Ideally this and more information about contribution would be included either in the README file or in the CONTRIBUTIONS file of the project. So I opened an issue asking if they would be interested in it.

💖 💪 🙅 🚩
szabgab
Gabor Szabo

Posted on March 11, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related