Skip to content

Commit dcbaae3

Browse files
committed
DOC: Explain how to run the tests without other pytest plugins
pytest loads every plugin installed in the environment, and the strict test configuration turns a marker that a plugin uses but linearmodels does not register into an error. In the FreeBSD report (xref #853), test_runner and test_extra_args failed with "'gpu' not found in markers configuration option": linearmodels.test() starts a second pytest session in the same process, and a plugin of that environment used the marker there. The README now shows how to run the tests, and how to run them with PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 and pytest-xdist loaded explicitly. A stand-in plugin that uses an unregistered marker fails the same two tests with the same message, and they pass with the environment variable. The testing requirements also list xarray, which the tests import, and pytest-xdist.
1 parent 5cc05f2 commit dcbaae3

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,47 @@ python -m pip install -r requirements.txt -r requirements-dev.txt
125125
python -m pip install -e . --no-build-isolation
126126
```
127127

128+
## Running the tests
129+
130+
The tests are installed with linearmodels. They need pytest 9 and xarray, and
131+
pytest-xdist to run in parallel.
132+
133+
```bash
134+
python -c "import linearmodels; linearmodels.test(['--skip-slow', '-n', 'auto'])"
135+
```
136+
137+
`--skip-slow` skips the slow tests and `--skip-examples` the example notebooks.
138+
139+
pytest loads every plugin that is installed in the environment, and the test
140+
configuration of linearmodels is strict, so that, for example, a marker that is
141+
not registered is an error. A plugin that uses such a marker makes tests fail
142+
with a message such as `'gpu' not found in markers configuration option`. To run
143+
the tests without the other plugins, turn off their automatic loading and load
144+
pytest-xdist explicitly. This works with `python -m pytest` too.
145+
146+
```bash
147+
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -c "import linearmodels; linearmodels.test(['-p', 'xdist', '-n', 'auto'])"
148+
```
149+
150+
When the tests run in several processes with pytest-xdist, limit the BLAS
151+
libraries to one thread in each process. Otherwise every process starts as many
152+
threads as there are cores, and excessive context switching makes the tests run
153+
very slow. This problem is particularly acute on machines with high CPU counts.
154+
155+
```bash
156+
export MKL_NUM_THREADS=1
157+
export OPENBLAS_NUM_THREADS=1
158+
export OMP_NUM_THREADS=1
159+
```
160+
161+
or, in PowerShell,
162+
163+
```powershell
164+
$env:MKL_NUM_THREADS = 1
165+
$env:OPENBLAS_NUM_THREADS = 1
166+
$env:OMP_NUM_THREADS = 1
167+
```
168+
128169
## Documentation
129170

130171
[Stable Documentation](https://bashtage.github.io/linearmodels/) is
@@ -173,6 +214,8 @@ Python, NumPy and the other dependencies.
173214
### Testing
174215

175216
- pytest (9.0+)
217+
- xarray (0.16+)
218+
- pytest-xdist (optional, to run the tests in parallel)
176219

177220
### Documentation
178221

0 commit comments

Comments
 (0)