Skip to content

Commit

Permalink
Fix: small edits from review
Browse files Browse the repository at this point in the history
  • Loading branch information
lwasser committed Jan 9, 2024
1 parent 0455fa7 commit 279d05f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Binary file added images/python-package-test-tools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/test-tools.png
Binary file not shown.
30 changes: 22 additions & 8 deletions tests/run-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ is working as expected. However, it's also important to think about your code ru
On this page, you will learn about the tools that you can use to both run tests in isolated environments and across
Python versions.



### Tools to run your tests

There are three types of tools that will make is easier to setup and run your tests in various environments:
Expand All @@ -18,7 +20,7 @@ There are three types of tools that will make is easier to setup and run your te
3. **Continuous Integration (CI):** is the last tool that you'll need to run your tests. CI will not only allow you to replicate any automated builds you create using nox or tox to run your package in different Python environments. It will also allow you to run your tests on different operating systems (Windows, Mac and Linux). [We discuss using CI to run tests here](tests-ci).

:::{figure-md}
![Figure showing three boxes - the first has Test Frameworks in it, the second Test Runner and the third Continuous Integration....](../images/test-tools.png)
![Figure showing three boxes - the first has Test Frameworks in it, the second Test Runner and the third Continuous Integration....](../images/python-package-test-tools.png)

There are three types of tools that will help you develop and run your tests. Test frameworks like pytest
provide syntax and a **framework** for you to write and
Expand Down Expand Up @@ -97,9 +99,14 @@ with it. Make also won't manage environments for you like **nox** will do.
set up virtual environments, and run tests across Python versions using the environment manager of your choice with a
single command.

:::{note} Nox Installations

When you use nox to run tests across different Python versions, nox will create and manage individual `venv` environments for each Python version that you specify in the nox function. It will setup everything that you need to run tests in each environment for you.
:::

Nox can also be used for other development tasks such as building
documentation, creating your package distribution, and testing across various
environment managers such as `conda` and `pip`.
documentation, creating your package distribution, and testing installations
across both PyPI related environments (e.g. venv, virtualenv) and `conda` (e.g. `conda-forge`).

## Test Environments

Expand All @@ -113,17 +120,24 @@ Note that for the code below to work, you need to have all 4 versions of Python

### Nox with venv environments

```{admonition} TODO:
```{todo}
TODO: add some tests above and show what the output would look like in the examples below...
```

Below is an example of setting up nox to run tests using `venv` which is the built in environment manager that comes with base Python.

Note that the example below assumes that you have [setup your `pyproject.toml` to declare test dependencies in a way that pip
can understand](../package-structure-code/declare-dependencies.md). An example of that setup is below.
can understand](../package-structure-code/declare-dependencies.md). An example
of that setup is below.

```toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "pyosPackage"
version = "0.1.0"
dependencies = [
"geopandas",
"xarray",
Expand Down Expand Up @@ -157,9 +171,9 @@ Above you create a nox session in the form of a function
with a `@nox.session` decorator. Notice that within the decorator you declare the versions of python that you
wish to run.

To run the above you'd use the command where `-s` stands for
session. Your function above is called test, therefore
the session name is test.
To run the above you'd use the command where `--session`. You may also see
people useing the shortcut for session `-s`. Your function above
is called test, therefor the session name is test.

```
nox -s test
Expand Down

0 comments on commit 279d05f

Please sign in to comment.