conftest.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 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, NghttpxQuic, NghttpxFwd
  32. @pytest.fixture(scope="package")
  33. def env(pytestconfig) -> Env:
  34. env = Env(pytestconfig=pytestconfig)
  35. level = logging.DEBUG if env.verbose > 0 else logging.INFO
  36. logging.getLogger('').setLevel(level=level)
  37. if not env.curl_has_protocol('http'):
  38. pytest.skip("curl built without HTTP support")
  39. if not env.curl_has_protocol('https'):
  40. pytest.skip("curl built without HTTPS support")
  41. if env.setup_incomplete():
  42. pytest.skip(env.incomplete_reason())
  43. env.setup()
  44. if not env.make_clients():
  45. pytest.exit(1)
  46. return env
  47. @pytest.fixture(scope="package", autouse=True)
  48. def log_global_env_facts(record_testsuite_property, env):
  49. record_testsuite_property("http-port", env.http_port)
  50. @pytest.fixture(scope='package')
  51. def httpd(env) -> Httpd:
  52. httpd = Httpd(env=env)
  53. if not httpd.exists():
  54. pytest.skip(f'httpd not found: {env.httpd}')
  55. httpd.clear_logs()
  56. if not httpd.start():
  57. pytest.fail(f'failed to start httpd: {env.httpd}')
  58. yield httpd
  59. httpd.stop()
  60. @pytest.fixture(scope='package')
  61. def nghttpx(env, httpd) -> Optional[Nghttpx]:
  62. nghttpx = NghttpxQuic(env=env)
  63. if env.have_h3():
  64. nghttpx.clear_logs()
  65. assert nghttpx.start()
  66. yield nghttpx
  67. nghttpx.stop()
  68. @pytest.fixture(scope='package')
  69. def nghttpx_fwd(env, httpd) -> Optional[Nghttpx]:
  70. nghttpx = NghttpxFwd(env=env)
  71. if env.have_h3():
  72. nghttpx.clear_logs()
  73. assert nghttpx.start()
  74. yield nghttpx
  75. nghttpx.stop()