Automated Testing in Python with pytest, tox, and GitHub Actions
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about Python project layout, editable installs, import errors and tox configuration, since it shows a modern packaging and testing setup step by step.
Recommended by 1 people across 1 different months, 2021 to 2024.
What it is
A 27-minute mCoding tutorial by James Murphy that turns a plain Python project into an installable package with automated tests. It uses pytest, mypy and flake8, runs them in isolated environments with tox, and triggers them on GitHub pushes and pull requests via GitHub Actions.
What people said
Recommends Jesse · 2022-09 · Stack Overflow · on “Can't import modules in Python”
I also found this part of python extremely confusing. You basically need to make your project an installable package and do an editable install of it in your environment to import your modules this way. I would recommend this youtube video [this video] for a great walkthrough on the process, you only need to watch 2:36-8:36 for this topic specifically but the whole video is quite useful. Best of luck.
Cites Oli · 2021-09 · Stack Overflow · on “ModuleNotFoundError: No module named 'src' when building python project using pyb -v”
It looks like you need to do `from amass import amass` to make pybuilder work. To make intellij also work with this, you can install the `amass` package into your virtualenv, preferably in editable mode, so that you don't have to reinstall the package every time you change the code. This video is relevant (although doesn't mention pybuilder): [this video]
Cites Phoenix · 2021-12 · Stack Overflow · on “Most "Pythonic" way to have package install dependencies based on GPU presence/manufacturer?”
I am currently developing a Machine Learning library that allows users to write CPU/GPU agnostic code to achieve certain tasks. In order to run the GPU enabled code, my package has certain dependencies which are only compatible with CUDA-enabled NVIDIA GPUs. Therefore, I would like my package to only install those dependencies when a user installs my package on a device with CUDA-enabled GPU. I researched how to do this, and at first it seemed as though my answer was going to be in PEP 508 [LINK] . Howevever, the environment markers described in this PEP do not include the presence of a GPU, let alone the manufacturer and/or drivers of that GPU. Therefore, I am looking to see what the most "
Cites dafrandle · 2022-04 · Stack Overflow · on “tox refuses to use deps setting in py38 and various pip problems”
I have a Django project that i'm trying to set up unit testing with tox in. here is the directory structure: + djangoProject | +-.github +-.pytest +-.tox +- api +- blog +- djangoProject +- templates | + .gitignore + manage.py + pyproject.toml + requirements.txt + requirements_dev.txt + setup.cfg + tox.ini Here are the various config files tox.ini : [tox] minversion = 3.8.0 envlist = py38, py39, py310, flake8 isolated_build = true [testenv] setenv = PYTHONPATH = {toxinidir} deps = -r{toxinidir}/requirements_dev.txt commands = pytest --basetemp={envtmpdir} [testenv:flake8] basepython = python3.8 deps = flake8 commands = flake8 pyproject.toml : [build-system] requires = ["setuptools>=42.0", "wh
Cites Benny Jobigan · 2024-05 · Stack Overflow · on “How to deal with a python project dependency that "must exist" in the env but can't be installed?”
I don't have a lot of experience with python project organization, but I've been trying to follow modern best practices using a pyproject.toml [LINK] and structure as in this video [this video] (minus the ci bits). This is ultimately a geoprocessing tool for ArcGIS Pro, though I've tried to abstract the logic of the tool from the 'backend' calls to ArcGIS Pro so that I could create other backends in the future, for example for QGIS or geopandas and rasterio. However, the arcpy module that allows one to interface with ArcGIS Pro is not a module you can just install into your environment from pypi. It simply "exists" in the conda environment provided by the install of ArcGIS Pro. I've been writing