You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/run-tests.md
+22-8Lines changed: 22 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ is working as expected. However, it's also important to think about your code ru
9
9
On this page, you will learn about the tools that you can use to both run tests in isolated environments and across
10
10
Python versions.
11
11
12
+
13
+
12
14
### Tools to run your tests
13
15
14
16
There are three types of tools that will make is easier to setup and run your tests in various environments:
@@ -18,7 +20,7 @@ There are three types of tools that will make is easier to setup and run your te
18
20
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).
19
21
20
22
:::{figure-md}
21
-

23
+

22
24
23
25
There are three types of tools that will help you develop and run your tests. Test frameworks like pytest
24
26
provide syntax and a **framework** for you to write and
@@ -97,9 +99,14 @@ with it. Make also won't manage environments for you like **nox** will do.
97
99
set up virtual environments, and run tests across Python versions using the environment manager of your choice with a
98
100
single command.
99
101
102
+
:::{note} Nox Installations
103
+
104
+
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.
105
+
:::
106
+
100
107
Nox can also be used for other development tasks such as building
101
-
documentation, creating your package distribution, and testing across various
102
-
environment managers such as `conda`and `pip`.
108
+
documentation, creating your package distribution, and testing installations
109
+
across both PyPI related environments (e.g. venv, virtualenv) and `conda`(e.g. `conda-forge`).
103
110
104
111
## Test Environments
105
112
@@ -113,17 +120,24 @@ Note that for the code below to work, you need to have all 4 versions of Python
113
120
114
121
### Nox with venv environments
115
122
116
-
```{admonition} TODO:
123
+
```{todo}
117
124
TODO: add some tests above and show what the output would look like in the examples below...
118
125
```
119
126
120
127
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.
121
128
122
129
Note that the example below assumes that you have [setup your `pyproject.toml` to declare test dependencies in a way that pip
123
-
can understand](../package-structure-code/declare-dependencies.md). An example of that setup is below.
130
+
can understand](../package-structure-code/declare-dependencies.md). An example
131
+
of that setup is below.
124
132
125
133
```toml
134
+
[build-system]
135
+
requires = ["hatchling"]
136
+
build-backend = "hatchling.build"
137
+
126
138
[project]
139
+
name = "pyosPackage"
140
+
version = "0.1.0"
127
141
dependencies = [
128
142
"geopandas",
129
143
"xarray",
@@ -157,9 +171,9 @@ Above you create a nox session in the form of a function
157
171
with a `@nox.session` decorator. Notice that within the decorator you declare the versions of python that you
158
172
wish to run.
159
173
160
-
To run the above you'd use the command where `-s` stands for
161
-
session. Your function above is called test, therefore
162
-
the session name is test.
174
+
To run the above you'd use the command where `--session`. You may also see
175
+
people using the shortcut for session`-s`. Your function above
176
+
is called test, therefore the session name is test.
Copy file name to clipboardExpand all lines: tests/tests-ci.md
+14-19Lines changed: 14 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -19,11 +19,22 @@ locally.
19
19
20
20
## Example GitHub action that runs tests
21
21
22
-
Below is an example github action that runs tests using nox
22
+
Below is an example GitHub action that runs tests using nox
23
23
across both Windows, Mac and Linux and on Python versions
24
24
3.9-3.11. It also includes two steps that make your build more
25
25
efficient so your dependencies aren't downloaded multiple times.
26
26
27
+
To work properly, this file should be located in a root directory of your
28
+
GitHub repository:
29
+
30
+
```bash
31
+
pyospackage/
32
+
├──.github/
33
+
└── workflows/
34
+
└── run-tests.yml # The name of this file can be whatever you wish
35
+
```
36
+
37
+
27
38
```yaml
28
39
name: Pytest unit/integration
29
40
@@ -50,27 +61,10 @@ jobs:
50
61
51
62
steps:
52
63
- uses: actions/checkout@v4
53
-
with:
54
-
# fetch more than the last single commit to help scm generate proper version
55
-
fetch-depth: 20
56
64
- name: Set up Python ${{ matrix.python-version }}
57
65
uses: actions/setup-python@v4
58
66
with:
59
67
python-version: ${{ matrix.python-version }}
60
-
cache: pip # By adding cache here, you are telling actions to reuse installed dependencies rather than re-downloading and installing them each time. This speeds up your workflow
61
-
62
-
# This step and the step below are an optional steps to cache variables to make your build faster / more efficient
0 commit comments