_tester.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """
  2. Entrypoint for testing from the top-level namespace.
  3. """
  4. from __future__ import annotations
  5. import os
  6. import sys
  7. from pandas.compat._optional import import_optional_dependency
  8. PKG = os.path.dirname(os.path.dirname(__file__))
  9. def test(extra_args: list[str] | None = None, run_doctests: bool = False) -> None:
  10. """
  11. Run the pandas test suite using pytest.
  12. By default, runs with the marks -m "not slow and not network and not db"
  13. Parameters
  14. ----------
  15. extra_args : list[str], default None
  16. Extra marks to run the tests.
  17. run_doctests : bool, default False
  18. Whether to only run the Python and Cython doctests. If you would like to run
  19. both doctests/regular tests, just append "--doctest-modules"/"--doctest-cython"
  20. to extra_args.
  21. Examples
  22. --------
  23. >>> pd.test() # doctest: +SKIP
  24. running: pytest...
  25. """
  26. pytest = import_optional_dependency("pytest")
  27. import_optional_dependency("hypothesis")
  28. cmd = ["-m not slow and not network and not db"]
  29. if extra_args:
  30. if not isinstance(extra_args, list):
  31. extra_args = [extra_args]
  32. cmd = extra_args
  33. if run_doctests:
  34. cmd = [
  35. "--doctest-modules",
  36. "--doctest-cython",
  37. f"--ignore={os.path.join(PKG, 'tests')}",
  38. ]
  39. cmd += [PKG]
  40. joined = " ".join(cmd)
  41. print(f"running: pytest {joined}")
  42. sys.exit(pytest.main(cmd))
  43. __all__ = ["test"]