Skip to content

Commit d716f06

Browse files
cgoldbergharsha509
andauthored
Add tox for Python testing (#2285)
* Add tox for Python testing * Update README.md --------- Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com>
1 parent 46c35d6 commit d716f06

File tree

3 files changed

+67
-13
lines changed

3 files changed

+67
-13
lines changed

examples/python/README.md

+36-13
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,61 @@
1-
# Running all tests from Selenium python example
1+
# Running tests from Selenium Python examples
22

3-
Follow these steps to run all test example from selenium python
4-
5-
1. Clone this repository
3+
#### 1. Clone this repository
64

75
```
86
git clone https://github.com/SeleniumHQ/seleniumhq.github.io.git
97
```
108

11-
2. Navigate to `python` directory
9+
#### 2. Navigate to `python` directory
1210

1311
```
1412
cd seleniumhq.github.io/examples/python
1513
```
1614

17-
3. Install dependencies using pip
15+
#### 3. Create a virtual environment
16+
17+
- On Windows:
18+
19+
```
20+
py -m venv venv
21+
venv\Scripts\activate
22+
```
23+
24+
- On Linux/Mac:
25+
26+
```
27+
python3 -m venv venv
28+
source venv/bin/activate
29+
```
30+
31+
#### 4. Install dependencies:
1832

1933
```
2034
pip install -r requirements.txt
2135
```
22-
> if you are on a different python version, for example python3.x you may have to replace `pip` with `pip3`
2336

24-
4. Run all tests
37+
> for help, see: https://packaging.python.org/en/latest/tutorials/installing-packages
38+
39+
#### 5. Run tests
40+
41+
- Run all tests with the default Python interpreter:
2542

2643
```
2744
pytest
2845
```
2946

30-
> Please keep some patience - If you are doing it for the first time, it will take a little while to verify and download the browser drivers
47+
- Run all tests with every installed/supported Python interpreter:
3148

32-
## Execute a specific example
33-
To run a specific Selenium Python example, use the following command:
34-
```bash
49+
```
50+
tox
51+
```
52+
53+
> Please have some patience - If you are doing it for the first time, it will take a little while to download the browser drivers
54+
55+
- Run a specific example:
56+
57+
```
3558
pytest path/to/test_script.py
3659
```
3760

38-
Make sure to replace `path/to/test_script.py` with the path and name of the example you want to run.
61+
> Make sure to replace `path/to/test_script.py` with the path and name of the example you want to run

examples/python/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pytest-trio==0.8.0
55
pytest-rerunfailures==15.0
66
flake8==7.2.0
77
requests==2.32.3
8+
tox==4.25.0

examples/python/tox.ini

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Tox (https://tox.wiki/) is a tool for running tests in multiple
2+
# virtualenvs. This configuration file will run the test suite on all
3+
# supported python versions. To use it, run "tox" from this directory.
4+
#
5+
# For a specific environment, run: "tox -e <env>" (i.e.: "tox -e py313")
6+
#
7+
# This tox configuration will skip any Python interpreters that can't be found.
8+
# To manage multiple Python interpreters for covering all versions, you can use
9+
# pyenv: https://github.com/pyenv/pyenv
10+
11+
12+
[tox]
13+
env_list =
14+
py39
15+
py310
16+
py311
17+
py312
18+
py313
19+
skip_missing_interpreters = True
20+
21+
[testenv]
22+
description = run tests
23+
passenv = *
24+
deps =
25+
-r requirements.txt
26+
commands =
27+
# "-vv" means extra verbose
28+
# "-r fEsxXp" means show extra test summary info as specified by:
29+
# (f)ailed, (E)rror, (s)kipped, (x)failed, (X)passed, (p)assed
30+
pytest -vv -r fEsxXp {posargs:.}

0 commit comments

Comments
 (0)