Skip to content

Commit c5e7234

Browse files
Update Blog “sivayanama-testing-opsramp-apis-with-pytest-fixtures”
1 parent bcc2e89 commit c5e7234

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

content/blog/sivayanama-testing-opsramp-apis-with-pytest-fixtures.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,66 @@ disable: false
1010

1111
# Sivayanama - Testing OpsRamp APIs with PyTest Fixtures
1212

13+
<!--EndFragment-->
14+
15+
16+
17+
OpsRamp platform  provides rich set of APIs. By using these APIs customers can build soultion to automate various ITOM workflows such as discovery and monitoring , event and incident mangement and remidiation and automation. Testing these APIs, automated solution  are very critical to ensure reliability and stability of the same. PyTest is a powerful python testing framework and it is widely used to test APIs. Fixtures is one of the most important capabilities of PyTest framework. In this article, we will discuss some advanced techniques of testing OpsRamp APIs using PyTest fixtures.
18+
19+
20+
21+
What Fixtures are 
22+
23+
PyTest fixtures are a special type of python function that provision fixed base line for testing.With the help of this base line we can ensure tests are run in reliable manner and produce consistent results and the same tests can be repeatable.
24+
25+
26+
27+
Install PyTest
28+
29+
Run the below command 
30+
31+
pip install -U pytest
32+
33+
 
34+
35+
Verify PyTest installation 
36+
37+
Run the below command 
38+
39+
 pytest --version
40+
41+
pytest 7.4.0
42+
43+
44+
45+
Define Fixture
46+
47+
We can define fixtures just by decorating a simple python function with [@pytest.fixture](https://docs.pytest.org/en/6.2.x/reference.html#pytest.fixture) for example 
48+
49+
50+
51+
import pytest
52+
53+
54+
55+
@pytest.fixture
56+
57+
def hello_world()
58+
59+
return 'Hello, Happy testing'
60+
61+
62+
63+
Invoking fixtures
64+
65+
Test functions can invoke fixtures just by declaring the required fixtures as arguments. 
66+
67+
68+
69+
def test_hello_world(hello_world)
70+
71+
assert hello_world == 'Hello, Happy testing'
72+
73+
74+
1375
<!--EndFragment-->

0 commit comments

Comments
 (0)