prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Have tests generate a certificate on-the-fly
  Unless we want to be doing https://github.com/scrapy/scrapy/pull/4650 every year, we should look into making tests generate a fresh certificate at run time.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `conftest.py`
  Content:
  ```
  1 from pathlib import Path
  2 
  3 import pytest
  4 
  5 
  6 def _py_files(folder):
  7     return (str(p) for p in Path(folder).rglob('*.py'))
  8 
  9 
  10 collect_ignore = [
  11     # not a test, but looks like a test
  12     "scrapy/utils/testsite.py",
  13     # contains scripts to be run by tests/test_crawler.py::CrawlerProcessSubprocess
  14     *_py_files("tests/CrawlerProcess"),
  15     # contains scripts to be run by tests/test_crawler.py::CrawlerRunnerSubprocess
  16     *_py_files("tests/CrawlerRunner"),
  17     # Py36-only parts of respective tests
  18     *_py_files("tests/py36"),
  19 ]
  20 
  21 for line in open('tests/ignores.txt'):
  22     file_path = line.strip()
  23     if file_path and file_path[0] != '#':
  24         collect_ignore.append(file_path)
  25 
  26 
  27 @pytest.fixture()
  28 def chdir(tmpdir):
  29     """Change to pytest-provided temporary directory"""
  30     tmpdir.chdir()
  31 
  32 
  33 def pytest_collection_modifyitems(session, config, items):
  34     # Avoid executing tests when executing `--flake8` flag (pytest-flake8)
  35     try:
  36         from pytest_flake8 import Flake8Item
  37         if config.getoption('--flake8'):
  38             items[:] = [item for item in items if isinstance(item, Flake8Item)]
  39     except ImportError:
  40         pass
  41 
  42 
  43 @pytest.fixture(scope='class')
  44 def reactor_pytest(request):
  45     if not request.cls:
  46         # doctests
  47         return
  48     request.cls.reactor_pytest = request.config.getoption("--reactor")
  49     return request.cls.reactor_pytest
  50 
  51 
  52 @pytest.fixture(autouse=True)
  53 def only_asyncio(request, reactor_pytest):
  54     if request.node.get_closest_marker('only_asyncio') and reactor_pytest != 'asyncio':
  55         pytest.skip('This test is only run with --reactor=asyncio')
  56
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/conftest.py b/conftest.py
  --- a/conftest.py
  +++ b/conftest.py
  @@ -2,6 +2,8 @@
   
   import pytest
   
  +from tests.keys import generate_keys
  +
   
   def _py_files(folder):
       return (str(p) for p in Path(folder).rglob('*.py'))
  @@ -53,3 +55,7 @@
   def only_asyncio(request, reactor_pytest):
       if request.node.get_closest_marker('only_asyncio') and reactor_pytest != 'asyncio':
           pytest.skip('This test is only run with --reactor=asyncio')
  +
  +
  +# Generate localhost certificate files, needed by some tests
  +generate_keys()
  
verification_info: {"golden_diff": "diff --git a/conftest.py b/conftest.py\n--- a/conftest.py\n+++ b/conftest.py\n@@ -2,6 +2,8 @@\n \n import pytest\n \n+from tests.keys import generate_keys\n+\n \n def _py_files(folder):\n     return (str(p) for p in Path(folder).rglob('*.py'))\n@@ -53,3 +55,7 @@\n def only_asyncio(request, reactor_pytest):\n     if request.node.get_closest_marker('only_asyncio') and reactor_pytest != 'asyncio':\n         pytest.skip('This test is only run with --reactor=asyncio')\n+\n+\n+# Generate localhost certificate files, needed by some tests\n+generate_keys()\n", "issue": "Have tests generate a certificate on-the-fly\nUnless we want to be doing https://github.com/scrapy/scrapy/pull/4650 every year, we should look into making tests generate a fresh certificate at run time.\n", "before_files": [{"content": "from pathlib import Path\n\nimport pytest\n\n\ndef _py_files(folder):\n    return (str(p) for p in Path(folder).rglob('*.py'))\n\n\ncollect_ignore = [\n    # not a test, but looks like a test\n    \"scrapy/utils/testsite.py\",\n    # contains scripts to be run by tests/test_crawler.py::CrawlerProcessSubprocess\n    *_py_files(\"tests/CrawlerProcess\"),\n    # contains scripts to be run by tests/test_crawler.py::CrawlerRunnerSubprocess\n    *_py_files(\"tests/CrawlerRunner\"),\n    # Py36-only parts of respective tests\n    *_py_files(\"tests/py36\"),\n]\n\nfor line in open('tests/ignores.txt'):\n    file_path = line.strip()\n    if file_path and file_path[0] != '#':\n        collect_ignore.append(file_path)\n\n\n@pytest.fixture()\ndef chdir(tmpdir):\n    \"\"\"Change to pytest-provided temporary directory\"\"\"\n    tmpdir.chdir()\n\n\ndef pytest_collection_modifyitems(session, config, items):\n    # Avoid executing tests when executing `--flake8` flag (pytest-flake8)\n    try:\n        from pytest_flake8 import Flake8Item\n        if config.getoption('--flake8'):\n            items[:] = [item for item in items if isinstance(item, Flake8Item)]\n    except ImportError:\n        pass\n\n\n@pytest.fixture(scope='class')\ndef reactor_pytest(request):\n    if not request.cls:\n        # doctests\n        return\n    request.cls.reactor_pytest = request.config.getoption(\"--reactor\")\n    return request.cls.reactor_pytest\n\n\n@pytest.fixture(autouse=True)\ndef only_asyncio(request, reactor_pytest):\n    if request.node.get_closest_marker('only_asyncio') and reactor_pytest != 'asyncio':\n        pytest.skip('This test is only run with --reactor=asyncio')\n", "path": "conftest.py"}], "after_files": [{"content": "from pathlib import Path\n\nimport pytest\n\nfrom tests.keys import generate_keys\n\n\ndef _py_files(folder):\n    return (str(p) for p in Path(folder).rglob('*.py'))\n\n\ncollect_ignore = [\n    # not a test, but looks like a test\n    \"scrapy/utils/testsite.py\",\n    # contains scripts to be run by tests/test_crawler.py::CrawlerProcessSubprocess\n    *_py_files(\"tests/CrawlerProcess\"),\n    # contains scripts to be run by tests/test_crawler.py::CrawlerRunnerSubprocess\n    *_py_files(\"tests/CrawlerRunner\"),\n    # Py36-only parts of respective tests\n    *_py_files(\"tests/py36\"),\n]\n\nfor line in open('tests/ignores.txt'):\n    file_path = line.strip()\n    if file_path and file_path[0] != '#':\n        collect_ignore.append(file_path)\n\n\n@pytest.fixture()\ndef chdir(tmpdir):\n    \"\"\"Change to pytest-provided temporary directory\"\"\"\n    tmpdir.chdir()\n\n\ndef pytest_collection_modifyitems(session, config, items):\n    # Avoid executing tests when executing `--flake8` flag (pytest-flake8)\n    try:\n        from pytest_flake8 import Flake8Item\n        if config.getoption('--flake8'):\n            items[:] = [item for item in items if isinstance(item, Flake8Item)]\n    except ImportError:\n        pass\n\n\n@pytest.fixture(scope='class')\ndef reactor_pytest(request):\n    if not request.cls:\n        # doctests\n        return\n    request.cls.reactor_pytest = request.config.getoption(\"--reactor\")\n    return request.cls.reactor_pytest\n\n\n@pytest.fixture(autouse=True)\ndef only_asyncio(request, reactor_pytest):\n    if request.node.get_closest_marker('only_asyncio') and reactor_pytest != 'asyncio':\n        pytest.skip('This test is only run with --reactor=asyncio')\n\n\n# Generate localhost certificate files, needed by some tests\ngenerate_keys()\n", "path": "conftest.py"}]}