From 6a3fc8a04bdcc1d8df64d4ff5661c3c6b7c8bd0c Mon Sep 17 00:00:00 2001 From: Satoshi Fujii Date: Wed, 30 Jun 2021 07:14:12 +0000 Subject: Fix pytest failure if http_proxy is set Test "tests.test_binding.test_resolve_all" (in test_binding.py) fails if proxy environment variable http_proxy is set. httpretty mock is ignored and an actual request is sent to non-existing address. By this change proxy variable is unset during the test. Signed-off-by: Satoshi Fujii Issue-ID: DCAEGEN2-2834 Change-Id: Ie0d4bc41f6f83d7cfdd3abaa3266ff8ac5a91c2e --- Changelog.md | 2 ++ tests/test_binding.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 8eec718..4c9a6c6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Cleanup code - Removed extraneous parentheses +### Fixed +- pytest fails if http\_proxy is set ## [2.3.0.] - 18/06/2021 diff --git a/tests/test_binding.py b/tests/test_binding.py index 010c63d..6c8b0ef 100644 --- a/tests/test_binding.py +++ b/tests/test_binding.py @@ -17,6 +17,8 @@ # limitations under the License. # ============LICENSE_END========================================================= +import os +import pytest import requests import httpretty import subprocess @@ -32,8 +34,17 @@ mr_url = 'http://mrrouter.onap.org:3904' intopic = 'VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT' outopic = 'POLICY-HILOTCA-EVENT-OUTPUT' + +@pytest.fixture() +def disable_proxy(monkeypatch): + if 'http_proxy' in os.environ: + monkeypatch.delenv('http_proxy') + if 'HTTP_PROXY' in os.environ: + monkeypatch.delenv('HTTP_PROXY') + + @httpretty.activate -def test_resolve_all(): +def test_resolve_all(disable_proxy): htbtmsg = '{"event":{"commonEventHeader":{"startEpochMicrosec":1518616063564475,"sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","eventId":"10048640","reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","priority":"Normal","version":3,"reportingEntityName":"TESTVM","sequence":10048640,"domain":"heartbeat","lastEpochMicrosec":1518616063564476,"eventName":"Heartbeat_vVnf","sourceName":"TESTVM","nfNamingCode":"vVNF"}}}' send_url = mr_url+'/events/'+intopic+'/DefaultGroup/1?timeout=15000' print(send_url) -- cgit 1.2.3-korg