Attempting to run tests

I am attempting to contribute to maas and am working on fixing some tests. I am doing my development on a vagrant box with the following vagrant file

Vagrant.configure('2') do |config|
  config.vm.box = 'bento/ubuntu-18.04'
  config.vm.provision 'shell', inline: <<-SHELL
    cd /vagrant
    sudo apt-get update
    make install-dependencies
    ./utilities/configure-lxd-profile
  SHELL
end

The HACKING.rst document specifies that individual tests can be run by passing ./bin/test.region path/to/test/file

However, when I run the following, every test fails with a twisted.internet.error.ReactorAlreadyRunning error

vagrant@vagrant:/vagrant$ ./bin/test.region src/provisioningserver/drivers/power/tests/test_redfish.py 
...
======================================================================
ERROR: provisioningserver.drivers.power.tests.test_redfish.TestRedfishPowerDriver.test_redfish_request_retries_404s_trailing_slash
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 133, in run
    self.runTest(result)
  File "/usr/lib/python3/dist-packages/nose/case.py", line 151, in runTest
    test(result)
  File "/vagrant/src/maastesting/testcase.py", line 279, in __call__
    super(MAASTestCase, self).__call__(result)
  File "/vagrant/src/maastesting/scenarios.py", line 34, in __call__
    super(WithScenarios, self).__call__(result)
  File "/home/vagrant/.buildout/eggs/unittest2-1.1.0-py3.6.egg/unittest2/case.py", line 673, in __call__
    return self.run(*args, **kwds)
  File "/vagrant/src/maastesting/testcase.py", line 275, in run
    super(MAASTestCase, self).run(result)
  File "/home/vagrant/.buildout/eggs/testscenarios-0.5.0-py3.6.egg/testscenarios/testcase.py", line 65, in run
    return super(WithScenarios, self).run(result)
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/testcase.py", line 671, in run
    return run_test.run(result)
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/runtest.py", line 80, in run
    return self._run_one(actual_result)
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/runtest.py", line 94, in _run_one
    return self._run_prepared_result(ExtendedToOriginalDecorator(result))
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/runtest.py", line 108, in _run_prepared_result
    self._run_core()
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/twistedsupport/_runtest.py", line 432, in _run_core
    spinner)
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/twistedsupport/_runtest.py", line 393, in _blocking_run_deferred
    spinner.run, self._timeout, self._run_deferred)
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/twistedsupport/_spinner.py", line 77, in trap_unhandled_errors
    result = function(*args, **kwargs)
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/twistedsupport/_spinner.py", line 49, in decorated
    return function(*args, **kwargs)
  File "/home/vagrant/.buildout/eggs/testtools-2.2.0-py3.6.egg/testtools/twistedsupport/_spinner.py", line 295, in run
    self._reactor.run()
  File "/usr/lib/python3/dist-packages/twisted/internet/asyncioreactor.py", line 266, in run
    self.startRunning(installSignalHandlers=installSignalHandlers)
  File "/usr/lib/python3/dist-packages/twisted/internet/base.py", line 1222, in startRunning
    ReactorBase.startRunning(self)
  File "/usr/lib/python3/dist-packages/twisted/internet/base.py", line 728, in startRunning
    raise error.ReactorAlreadyRunning()
twisted.internet.error.ReactorAlreadyRunning

These tests do not fail with this error when running make test. Is there some additional setup needed in order to run the granular tests? It would really speed up my iteration time.

tl;dr: try bin/test.rack src/provisioningserver/drivers/power/tests/test_redfish.py instead

The code in MAAS is architecturally split between things that the rack controller will run and things that the region controller will run. Power control is a responsibility of the rack controller, and doesn’t need the extra setup that region controller tests need.

We’re aware that some of our docs are out of date, and are looking to move it onto Discourse in the near future. Keep an eye out for a post coming ‘soon’ with info on how to setup a MAAS development environment and run tests etc.

Thank you, that will help me an awful lot