prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Migrate tests from unittest to pytest
  Our existing test suite has been written with the Python [`unittest`](https://docs.python.org/3/library/unittest.html) framework. However, as the test suite has grown and opsdroid has become more complex we are running into issues with the tests. Mainly around setting up and tearing down tests.
  
  The @opsdroid/maintainers team have decided that we want to migrate all tests to be written with the [`pytest`](https://docs.pytest.org/en/latest/contents.html) framework instead so that we can make better use of fixtures. Fixtures are more reusable and portable and should help reduce complexity all over.
  
  There's a lot to be done but it can be done piece by piece as `pytest` can run tests in either format. So if you wish to help in the effort you can start by searching the codebase for unittest suites. These are classes which are subclassed from `unittest.TestCase` or `asynctest.TestCase`, so searching all files for `unittest.TestCase` and `asynctest.TestCase` should be a good place to start.
  
  For detailed information on running the test suite and contributing to opsdroid [see the docs](https://docs.opsdroid.dev/en/latest/contributing/index.html). But the quickest way to get started us with [`tox`](https://tox.readthedocs.io/en/latest/).
  
  ```bash
  pip install -U tox  # You only need to install tox once
  
  tox -e py36,lint  # Run the Python 3.6 tests (the lowest version we support) and the linter
  ```
  
  Once you have found a test suite you wish to convert there are a few steps you need to follow to convert from unittest to pytest:
  - Move tests from top level `tests` directory to a nested `tests` directory in opsdroid. Create one in an appropriate place if there isn't already one.
  - Remove test from class, pytest tests are just regular functions.
  - Change assertions to use regular `assert` or [pytest assertions](https://docs.pytest.org/en/latest/assert.html).
  - Mark async tests. In unittest we write async tests by using the `asynctest.TestCase`, but in pytest we decorate our tests with `@pytest.mark.asyncio` instead.
  - Move setup operations to fixtures. If a test class contains a `setUp` method anything created here should become a fixture. Check the existing fixtures in `conftest.py` before creating new ones.
  - Add docstrings to tests and fixtures to explain what they do. We have been pretty rubbish with this up until now and there are many tests which are not obvious in what they are testing.
  
  Here's an example:
  
  ```python
  # Before (unittest)
  import asynctest
  import asynctest.mock as mock
  
  from opsdroid.cli.start import configure_lang
  from opsdroid.core import OpsDroid
  from opsdroid.events import Message
  from opsdroid.matchers import match_regex
  from opsdroid import constraints
  
  
  class TestConstraints(asynctest.TestCase):
      """Test the opsdroid constraint decorators."""
  
      async def setUp(self):
          configure_lang({})
  
      async def getMockSkill(self):
          async def mockedskill(opsdroid, config, message):
              pass
  
          mockedskill.config = {}
          return mockedskill
  
      async def test_constrain_rooms_constrains(self):
          with OpsDroid() as opsdroid:
              skill = await self.getMockSkill()
              skill = match_regex(r".*")(skill)
              skill = constraints.constrain_rooms(["#general"])(skill)
              opsdroid.skills.append(skill)
  
              tasks = await opsdroid.parse(
                  Message(text="Hello", user="user", target="#random", connector=None)
              )
              self.assertEqual(len(tasks), 2)  # Just match_always and match_event
  ```
  
  ```python
  # After (pytest)
  import pytest
  
  from opsdroid.cli.start import configure_lang
  from opsdroid.core import OpsDroid
  from opsdroid.events import Message
  from opsdroid.matchers import match_regex
  from opsdroid import constraints
  
  
  configure_lang({})  # Required for our internationalization of error messages
  
  
  @pytest.fixture
  def opsdroid():
      """An instance of the OpsDroid class."""
      with OpsDroid() as opsdroid:
          yield opsdroid
  
  
  @pytest.fixture
  def mock_skill():
      """A skill which does nothing but follows the skill API."""
  
      async def mockedskill(opsdroid, config, message):
          pass
  
      mockedskill.config = {}
      return mockedskill
  
  
  @pytest.mark.asyncio
  async def test_constrain_rooms_constrains(opsdroid, mock_skill):
      """Test that with the room constraint a skill is not called."""
      skill = match_regex(r".*")(mock_skill)
      skill = constraints.constrain_rooms(["#general"])(skill)
      opsdroid.skills.append(skill)
  
      tasks = await opsdroid.parse(
          Message(text="Hello", user="user", target="#random", connector=None)
      )
      assert len(tasks) == 2  # Just match_always and match_event
  ```
  
  Fixtures such as the `opsdroid` fixture will be extremely useful in many tests, so we will be creating some standard ones like this which will be available in all tests. If you write a fixture that you think could be useful in other places please don't hesitate to contribute it to the `conftest.py` file.
  
  If you have any questions you can chat to us on [Matrix](https://riot.im/app/#/room/#opsdroid-general:matrix.org). We encourage you to get started and if you have issues or get stuck then open a [draft PR](https://github.blog/2019-02-14-introducing-draft-pull-requests/) with your changes and we can take a look.
  
  ---
  
  When this issue is complete the documentation about the migration should be removed from the testing docs.
  
  </issue>
  <code>
  [start of opsdroid/conftest.py]
  1 """Pytest config for all opsdroid tests."""
  2 from opsdroid.testing import opsdroid
  3 
  4 from opsdroid.cli.start import configure_lang
  5 
  6 __all__ = ["opsdroid"]
  7 
  8 configure_lang({})
  9
  [end of opsdroid/conftest.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/opsdroid/conftest.py b/opsdroid/conftest.py
  --- a/opsdroid/conftest.py
  +++ b/opsdroid/conftest.py
  @@ -1,8 +1,29 @@
   """Pytest config for all opsdroid tests."""
  +import pytest
  +
  +import asyncio
  +
   from opsdroid.testing import opsdroid
  +from opsdroid.connector import Connector
   
   from opsdroid.cli.start import configure_lang
   
   __all__ = ["opsdroid"]
   
   configure_lang({})
  +
  +
  +@pytest.fixture(scope="session")
  +def get_connector():
  +    def _get_connector(config={}):
  +        return Connector(config, opsdroid=opsdroid)
  +
  +    return _get_connector
  +
  +
  +@pytest.yield_fixture
  +def event_loop():
  +    """Create an instance of the default event loop for each test case."""
  +    loop = asyncio.get_event_loop_policy().new_event_loop()
  +    yield loop
  +    loop.close()
  
verification_info: {"golden_diff": "diff --git a/opsdroid/conftest.py b/opsdroid/conftest.py\n--- a/opsdroid/conftest.py\n+++ b/opsdroid/conftest.py\n@@ -1,8 +1,29 @@\n \"\"\"Pytest config for all opsdroid tests.\"\"\"\n+import pytest\n+\n+import asyncio\n+\n from opsdroid.testing import opsdroid\n+from opsdroid.connector import Connector\n \n from opsdroid.cli.start import configure_lang\n \n __all__ = [\"opsdroid\"]\n \n configure_lang({})\n+\n+\n+@pytest.fixture(scope=\"session\")\n+def get_connector():\n+    def _get_connector(config={}):\n+        return Connector(config, opsdroid=opsdroid)\n+\n+    return _get_connector\n+\n+\n+@pytest.yield_fixture\n+def event_loop():\n+    \"\"\"Create an instance of the default event loop for each test case.\"\"\"\n+    loop = asyncio.get_event_loop_policy().new_event_loop()\n+    yield loop\n+    loop.close()\n", "issue": "Migrate tests from unittest to pytest\nOur existing test suite has been written with the Python [`unittest`](https://docs.python.org/3/library/unittest.html) framework. However, as the test suite has grown and opsdroid has become more complex we are running into issues with the tests. Mainly around setting up and tearing down tests.\r\n\r\nThe @opsdroid/maintainers team have decided that we want to migrate all tests to be written with the [`pytest`](https://docs.pytest.org/en/latest/contents.html) framework instead so that we can make better use of fixtures. Fixtures are more reusable and portable and should help reduce complexity all over.\r\n\r\nThere's a lot to be done but it can be done piece by piece as `pytest` can run tests in either format. So if you wish to help in the effort you can start by searching the codebase for unittest suites. These are classes which are subclassed from `unittest.TestCase` or `asynctest.TestCase`, so searching all files for `unittest.TestCase` and `asynctest.TestCase` should be a good place to start.\r\n\r\nFor detailed information on running the test suite and contributing to opsdroid [see the docs](https://docs.opsdroid.dev/en/latest/contributing/index.html). But the quickest way to get started us with [`tox`](https://tox.readthedocs.io/en/latest/).\r\n\r\n```bash\r\npip install -U tox  # You only need to install tox once\r\n\r\ntox -e py36,lint  # Run the Python 3.6 tests (the lowest version we support) and the linter\r\n```\r\n\r\nOnce you have found a test suite you wish to convert there are a few steps you need to follow to convert from unittest to pytest:\r\n- Move tests from top level `tests` directory to a nested `tests` directory in opsdroid. Create one in an appropriate place if there isn't already one.\r\n- Remove test from class, pytest tests are just regular functions.\r\n- Change assertions to use regular `assert` or [pytest assertions](https://docs.pytest.org/en/latest/assert.html).\r\n- Mark async tests. In unittest we write async tests by using the `asynctest.TestCase`, but in pytest we decorate our tests with `@pytest.mark.asyncio` instead.\r\n- Move setup operations to fixtures. If a test class contains a `setUp` method anything created here should become a fixture. Check the existing fixtures in `conftest.py` before creating new ones.\r\n- Add docstrings to tests and fixtures to explain what they do. We have been pretty rubbish with this up until now and there are many tests which are not obvious in what they are testing.\r\n\r\nHere's an example:\r\n\r\n```python\r\n# Before (unittest)\r\nimport asynctest\r\nimport asynctest.mock as mock\r\n\r\nfrom opsdroid.cli.start import configure_lang\r\nfrom opsdroid.core import OpsDroid\r\nfrom opsdroid.events import Message\r\nfrom opsdroid.matchers import match_regex\r\nfrom opsdroid import constraints\r\n\r\n\r\nclass TestConstraints(asynctest.TestCase):\r\n    \"\"\"Test the opsdroid constraint decorators.\"\"\"\r\n\r\n    async def setUp(self):\r\n        configure_lang({})\r\n\r\n    async def getMockSkill(self):\r\n        async def mockedskill(opsdroid, config, message):\r\n            pass\r\n\r\n        mockedskill.config = {}\r\n        return mockedskill\r\n\r\n    async def test_constrain_rooms_constrains(self):\r\n        with OpsDroid() as opsdroid:\r\n            skill = await self.getMockSkill()\r\n            skill = match_regex(r\".*\")(skill)\r\n            skill = constraints.constrain_rooms([\"#general\"])(skill)\r\n            opsdroid.skills.append(skill)\r\n\r\n            tasks = await opsdroid.parse(\r\n                Message(text=\"Hello\", user=\"user\", target=\"#random\", connector=None)\r\n            )\r\n            self.assertEqual(len(tasks), 2)  # Just match_always and match_event\r\n```\r\n\r\n```python\r\n# After (pytest)\r\nimport pytest\r\n\r\nfrom opsdroid.cli.start import configure_lang\r\nfrom opsdroid.core import OpsDroid\r\nfrom opsdroid.events import Message\r\nfrom opsdroid.matchers import match_regex\r\nfrom opsdroid import constraints\r\n\r\n\r\nconfigure_lang({})  # Required for our internationalization of error messages\r\n\r\n\r\n@pytest.fixture\r\ndef opsdroid():\r\n    \"\"\"An instance of the OpsDroid class.\"\"\"\r\n    with OpsDroid() as opsdroid:\r\n        yield opsdroid\r\n\r\n\r\n@pytest.fixture\r\ndef mock_skill():\r\n    \"\"\"A skill which does nothing but follows the skill API.\"\"\"\r\n\r\n    async def mockedskill(opsdroid, config, message):\r\n        pass\r\n\r\n    mockedskill.config = {}\r\n    return mockedskill\r\n\r\n\r\n@pytest.mark.asyncio\r\nasync def test_constrain_rooms_constrains(opsdroid, mock_skill):\r\n    \"\"\"Test that with the room constraint a skill is not called.\"\"\"\r\n    skill = match_regex(r\".*\")(mock_skill)\r\n    skill = constraints.constrain_rooms([\"#general\"])(skill)\r\n    opsdroid.skills.append(skill)\r\n\r\n    tasks = await opsdroid.parse(\r\n        Message(text=\"Hello\", user=\"user\", target=\"#random\", connector=None)\r\n    )\r\n    assert len(tasks) == 2  # Just match_always and match_event\r\n```\r\n\r\nFixtures such as the `opsdroid` fixture will be extremely useful in many tests, so we will be creating some standard ones like this which will be available in all tests. If you write a fixture that you think could be useful in other places please don't hesitate to contribute it to the `conftest.py` file.\r\n\r\nIf you have any questions you can chat to us on [Matrix](https://riot.im/app/#/room/#opsdroid-general:matrix.org). We encourage you to get started and if you have issues or get stuck then open a [draft PR](https://github.blog/2019-02-14-introducing-draft-pull-requests/) with your changes and we can take a look.\r\n\r\n---\r\n\r\nWhen this issue is complete the documentation about the migration should be removed from the testing docs.\n", "before_files": [{"content": "\"\"\"Pytest config for all opsdroid tests.\"\"\"\nfrom opsdroid.testing import opsdroid\n\nfrom opsdroid.cli.start import configure_lang\n\n__all__ = [\"opsdroid\"]\n\nconfigure_lang({})\n", "path": "opsdroid/conftest.py"}]}