filescope.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from . import LoadScopeScheduling
  2. from py.log import Producer
  3. class LoadFileScheduling(LoadScopeScheduling):
  4. """Implement load scheduling across nodes, but grouping test test file.
  5. This distributes the tests collected across all nodes so each test is run
  6. just once. All nodes collect and submit the list of tests and when all
  7. collections are received it is verified they are identical collections.
  8. Then the collection gets divided up in work units, grouped by test file,
  9. and those work units get submitted to nodes. Whenever a node finishes an
  10. item, it calls ``.mark_test_complete()`` which will trigger the scheduler
  11. to assign more work units if the number of pending tests for the node falls
  12. below a low-watermark.
  13. When created, ``numnodes`` defines how many nodes are expected to submit a
  14. collection. This is used to know when all nodes have finished collection.
  15. This class behaves very much like LoadScopeScheduling, but with a file-level scope.
  16. """
  17. def __init__(self, config, log=None):
  18. super(LoadFileScheduling, self).__init__(config, log)
  19. if log is None:
  20. self.log = Producer("loadfilesched")
  21. else:
  22. self.log = log.loadfilesched
  23. def _split_scope(self, nodeid):
  24. """Determine the scope (grouping) of a nodeid.
  25. There are usually 3 cases for a nodeid::
  26. example/loadsuite/test/test_beta.py::test_beta0
  27. example/loadsuite/test/test_delta.py::Delta1::test_delta0
  28. example/loadsuite/epsilon/__init__.py::epsilon.epsilon
  29. #. Function in a test module.
  30. #. Method of a class in a test module.
  31. #. Doctest in a function in a package.
  32. This function will group tests with the scope determined by splitting
  33. the first ``::`` from the left. That is, test will be grouped in a
  34. single work unit when they reside in the same file.
  35. In the above example, scopes will be::
  36. example/loadsuite/test/test_beta.py
  37. example/loadsuite/test/test_delta.py
  38. example/loadsuite/epsilon/__init__.py
  39. """
  40. return nodeid.split("::", 1)[0]