Skip to content

Commit 72d5755

Browse files
committed
Update tox
1 parent a87334a commit 72d5755

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

tox/README.md

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,109 @@ $ tox --help
3535

3636
## How to use it?
3737

38-
?
38+
39+
`tox` is an environment orchestrator, it needs `tox.ini` configuration file to define what tools required to
40+
setup and execute on your project's test environment.
41+
42+
#### 1. A minimal configuration file
43+
44+
Create `tox.ini` with the following configuration:
45+
```ini
46+
[tox]
47+
skipsdist = true
48+
```
49+
50+
Then run `tox` command:
51+
```bash
52+
$ tox
53+
py: OK (0.15 seconds)
54+
congratulations :) (0.20 seconds)
55+
```
56+
57+
What's happened? Under the work directory, a `.tox` directory was created with the following contents:
58+
59+
```bash
60+
.tox
61+
└── py
62+
├── bin
63+
│   ├── activate
64+
│   ├── activate.csh
65+
│   ├── activate.fish
66+
│   ├── activate.nu
67+
│   ├── activate.ps1
68+
│   ├── activate_this.py
69+
│   ├── pip
70+
│   ├── pip3
71+
│   ├── pip-3.10
72+
│   ├── pip3.10
73+
│   ├── python -> /usr/bin/python3
74+
│   ├── python3 -> python
75+
│   ├── python3.10 -> python
76+
│   ├── wheel
77+
│   ├── wheel3
78+
│   ├── wheel-3.10
79+
│   └── wheel3.10
80+
├── lib
81+
│   └── python3.10
82+
├── pyvenv.cfg
83+
└── tmp
84+
85+
5 directories, 18 files
86+
```
87+
88+
You can see **py** is the default environment created by tox, and py version is what default in your machine.
89+
90+
#### 2. Define your environment list
91+
92+
You can control the environment creation by specifying the `env_list` or `envlist` option
93+
94+
```ini
95+
[tox]
96+
skipsdist = true
97+
env_list = py310,py311,py312
98+
```
99+
100+
Then run command `$tox` again, you can see these Python environments created under `.tox` directory,
101+
102+
```bash
103+
.tox
104+
├── py310
105+
│   ├── bin
106+
│   ├── lib
107+
│   ├── pyvenv.cfg
108+
│   └── tmp
109+
├── py311
110+
│   ├── bin
111+
│   ├── lib
112+
│   ├── pyvenv.cfg
113+
│   └── tmp
114+
└── py312
115+
├── bin
116+
├── lib
117+
├── pyvenv.cfg
118+
└── tmp
119+
120+
12 directories, 3 files
121+
```
122+
123+
What's about if you specify a Python version that does not exist on your system? For example, if I specify `py39` in `env_list` and Python 3.9
124+
is not installed on my machine, then `tox` would skip it and show the following information:
125+
126+
```bash
127+
py39: skipped because could not find python interpreter with spec(s): py39
128+
py39: SKIP ⚠ in 0.02 seconds
129+
```
130+
131+
#### 3. More on Configuration
132+
133+
There are two types of configurations: core settings `[tox]`, and per-run environment settings `[testenv]` and `[testenv:<envname>]`.
134+
135+
Except for the `tox.ini` configuration, `tox` supports `pyproject.toml` and `setup.cfg` as well. `tox` supports three configuration locations
136+
prioritized in the following order:
137+
1. `tox.ini`
138+
2. `pyproject.toml`
139+
3. `setup.cfg`
140+
39141

40142
For more information about `tox`, please refer to the [official documentation](https://tox.wiki/).
41143

tox/tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tox]
2+
skipsdist = true
3+
env_list = py39,py310,py311,py312

0 commit comments

Comments
 (0)