conftest.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 2008 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. # SPDX-License-Identifier: curl
  22. #
  23. ###########################################################################
  24. #
  25. import logging
  26. import os
  27. import sys
  28. from typing import Optional
  29. import pytest
  30. sys.path.append(os.path.join(os.path.dirname(__file__), '.'))
  31. from testenv import Env, Nghttpx, Httpd
  32. def pytest_report_header(config, startdir):
  33. return f"curl tests-httpd tests"
  34. def pytest_addoption(parser):
  35. parser.addoption("--repeat", action="store", type=int, default=1,
  36. help='Number of times to repeat each test')
  37. def pytest_generate_tests(metafunc):
  38. if "repeat" in metafunc.fixturenames:
  39. count = int(metafunc.config.getoption("repeat"))
  40. metafunc.fixturenames.append('tmp_ct')
  41. metafunc.parametrize('repeat', range(count))
  42. @pytest.fixture(scope="package")
  43. def env(pytestconfig) -> Env:
  44. env = Env(pytestconfig=pytestconfig)
  45. level = logging.DEBUG if env.verbose > 0 else logging.INFO
  46. logging.getLogger('').setLevel(level=level)
  47. env.setup()
  48. return env
  49. @pytest.fixture(scope='package')
  50. def httpd(env) -> Httpd:
  51. httpd = Httpd(env=env)
  52. assert httpd.exists(), f'httpd not found: {env.httpd}'
  53. httpd.clear_logs()
  54. assert httpd.start()
  55. yield httpd
  56. httpd.stop()
  57. @pytest.fixture(scope='package')
  58. def nghttpx(env) -> Optional[Nghttpx]:
  59. if env.have_h3_server():
  60. nghttpx = Nghttpx(env=env)
  61. nghttpx.clear_logs()
  62. assert nghttpx.start()
  63. yield nghttpx
  64. nghttpx.stop()
  65. return None