Thanks all in advance first. Hope to get some idea or solution to resolve the issues. I got an trouble during pytest for a unit testing on an artifacts `s value. However, the units testing is running under (
pytest -v ./resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py ) with following errors as a result.
E fixture 'circuits_app' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, requests_mock, tmp_path, tmp_path_factory, tmpdir, tmpdir_f
actory
> use 'pytest --fixtures [testpath]' for help on them.
from __future__ import print_function
import pytest
from resilient_circuits.util import get_config_data, get_function_definition
from resilient_circuits import SubmitTestFunction, FunctionResult
PACKAGE_NAME = "fn_cmdb_checking"
FUNCTION_NAME = "fn_cmdb_checking"
# Read the default configuration-data section from the package
config_data = get_config_data(PACKAGE_NAME)
# Provide a simulation of the Resilient REST API (uncomment to connect to a real appliance)
resilient_mock = "pytest_resilient_circuits.BasicResilientMock"
def call_fn_cmdb_checking_function(circuits, function_params, timeout=10):
# type: (object, object, object) -> object
# Fire a message to the function
evt = SubmitTestFunction("fn_cmdb_checking", function_params)
circuits.manager.fire(evt)
event = circuits.watcher.wait("fn_cmdb_checking_result", parent=evt, timeout=timeout)
assert event
assert isinstance(event.kwargs["result"], FunctionResult)
pytest.wait_for(event, "complete", True)
return event.kwargs["result"].value
class TestFnCmdbChecking:
""" Tests for the fn_cmdb_checking function"""
def test_function_definition(self):
""" Test that the package provides customization_data that defines the function """
func = get_function_definition(PACKAGE_NAME, FUNCTION_NAME)
assert func is not None
@pytest.mark.parametrize("artifact_id, expected_results", [
(123, {"value": "xyz"}),
(123, {"value": "xyz"}),
(330, {"value": "172.49.51.60"})
])
def test_success(self, circuits_app, artifact_id, expected_results):
""" Test calling with sample values for the parameters """
function_params = {
"artifact_id": artifact_id
}
results = call_fn_cmdb_checking_function(circuits_app, function_params)
assert(expected_results == results)
== test_fn_cmdb_checking.py ==
=================================================================================================================== 1 passed, 3 error in 0.53 seconds ===================================================================================================================
(resilient)[integration@psophklapi01 ~]$ cls
-bash: cls: command not found
(resilient)[integration@psophklapi01 ~]$ clear
(resilient)[integration@psophklapi01 ~]$ pytest -v ./resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py
========================================================================================================================== test session starts ==========================================================================================================================
platform linux2 -- Python 2.7.13, pytest-4.6.5, py-1.8.0, pluggy-0.12.0 -- /home/integration/resilient/bin/python
cachedir: .pytest_cache
rootdir: /home/integration/resilient/lib/python2.7/site-packages/fn_cmdb_checking
plugins: requests-mock-1.5.2
collected 4 items
resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py::TestFnCmdbChecking::test_function_definition PASSED [ 25%]
resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py::TestFnCmdbChecking::test_success[123-expected_results0] ERROR [ 50%]
resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py::TestFnCmdbChecking::test_success[123-expected_results1] ERROR [ 75%]
resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py::TestFnCmdbChecking::test_success[330-expected_results2] ERROR [100%]
================================================================================================================================ ERRORS =================================================================================================================================
_______________________________________________________________________________________________ ERROR at setup of TestFnCmdbChecking.test_success[123-expected_results0] ________________________________________________________________________________________________
file /home/integration/resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py, line 39
@pytest.mark.parametrize("artifact_id, expected_results", [
(123, {"value": "xyz"}),
(123, {"value": "xyz"}),
(330, {"value": "172.49.51.60"})
])
def test_success(self, circuits_app, artifact_id, expected_results):
E fixture 'circuits_app' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, requests_mock, tmp_path, tmp_path_factory, tmpdir, tmpdir_f
actory
> use 'pytest --fixtures [testpath]' for help on them.
/home/integration/resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py:39
_______________________________________________________________________________________________ ERROR at setup of TestFnCmdbChecking.test_success[123-expected_results1] ________________________________________________________________________________________________
file /home/integration/resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py, line 39
@pytest.mark.parametrize("artifact_id, expected_results", [
(123, {"value": "xyz"}),
(123, {"value": "xyz"}),
(330, {"value": "172.49.51.60"})
])
def test_success(self, circuits_app, artifact_id, expected_results):
E fixture 'circuits_app' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, requests_mock, tmp_path, tmp_path_factory, tmpdir, tmpdir_f
actory
> use 'pytest --fixtures [testpath]' for help on them.
/home/integration/resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py:39
_______________________________________________________________________________________________ ERROR at setup of TestFnCmdbChecking.test_success[330-expected_results2] ________________________________________________________________________________________________
file /home/integration/resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py, line 39
@pytest.mark.parametrize("artifact_id, expected_results", [
(123, {"value": "xyz"}),
(123, {"value": "xyz"}),
(330, {"value": "172.49.51.60"})
])
def test_success(self, circuits_app, artifact_id, expected_results):
E fixture 'circuits_app' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, requests_mock, tmp_path, tmp_path_factory, tmpdir, tmpdir_f
actory
> use 'pytest --fixtures [testpath]' for help on them.
/home/integration/resilient/lib/python2.7/site-packages/fn_cmdb_checking/tests/test_fn_cmdb_checking.py:39
=================================================================================================================== 1 passed, 3 error in 0.53 seconds ===================================================================================================================
(resilient)[integration@psophklapi01 ~]$
------------------------------
Ivan To
------------------------------