@@ -267,6 +267,73 @@ By following these steps, you will be able to effectively use the Scpdt pytest p
267
267
268
268
Happy testing!
269
269
270
+ ## Rough edges and sharp bits
271
+
272
+ Here is a (non-exhaustive) list of possible gotchas:
273
+
274
+ - * In-place development builds* .
275
+
276
+ Some tools (looking at you ` meson-python ` ) simulate in-place builds with a
277
+ ` build-install ` directory. If this directory is located under the project root,
278
+ ` pytest ` is getting confused by duplicated items under the root and build-install
279
+ folders.
280
+
281
+ The solution is to make pytest only look into the ` build-install ` directory
282
+ (the specific path to ` build-install ` may vary):
283
+
284
+ ```
285
+ $ pytest build-install/lib/python3.10/site-packages/scipy/ --doctest-modules
286
+ ```
287
+
288
+ instead of ` $ pytest --pyargs scipy ` .
289
+
290
+ If push comes to shove, you may try using the magic env variable:
291
+ ` PY_IGNORE_IMPORTMISMATCH=1 pytest ... ` ,
292
+ however the need usually indicates an issue with the package itself.
293
+ (see [ gh-107 ] ( https://github.com/ev-br/scpdt/pull/107 ) for an example).
294
+
295
+ - * Optional dependencies are not that optional*
296
+
297
+ If your package contains optional dependencies, doctests do not know about them
298
+ being optional. So you either guard the imports in doctests (yikes!), or
299
+ the collections fails if dependencies are not available.
300
+
301
+ The solution is to explicitly ` --ignore ` the paths to modules with optionals.
302
+ (or use ` DTConfig.pytest_extra_ignore ` list):
303
+
304
+ ```
305
+ $ pytest --ignore=/build-install/lib/scipy/python3.10/site-packages/scipy/_lib ...
306
+ ```
307
+
308
+ Note that installed packages are no different:
309
+
310
+ ```
311
+ $ pytest --pyargs scipy --doctest-modules --ignore=/path/to/installed/scipy/_lib
312
+ ```
313
+
314
+ - * Doctest collection strategies*
315
+
316
+ The default collection strategy follows ` doctest ` module and ` pytest ` . This leads
317
+ to duplicates if your package has the split between public and \_ private modules,
318
+ where public modules re-export things from private ones. The solution is to
319
+ use ` $ pytest --doctest-collect=api ` CLI switch: with this, only public
320
+ objects will be collected.
321
+
322
+ The decision on what is public is as follows: an object is public iff
323
+
324
+ - it is included into the ` __all__ ` list of a public module;
325
+ - the name of the object does not have a leading underscore;
326
+ - the name of the module from which the object is collected does not have
327
+ a leading underscore.
328
+
329
+ Consider an example: ` scipy.linalg.det ` is defined in ` scipy/linalg/_basic.py ` ,
330
+ so it is collected twice, from ` _basic.py ` and from ` __init__.py ` . The rule above
331
+ leads to
332
+
333
+ - ` scipy.linalg._basic.det ` , collected from ` scipy/linalg/_basic.py ` , is private.
334
+ - ` scipy.linalg.det ` , collected from ` scipy/linalg/__init__.py ` , is public.
335
+
336
+
270
337
## Prior art and related work
271
338
272
339
- ` pytest ` provides some limited floating-point aware ` NumericLiteralChecker ` .
0 commit comments