11# -*- coding: utf-8 -*-
2+ import json
23import pathlib
34import pytest
45import sqlite3
@@ -9,8 +10,8 @@ def test_monitor_basic_test(testdir):
910 # create a temporary pytest test module
1011 testdir .makepyfile ("""
1112 import time
12-
13-
13+
14+
1415 def test_ok():
1516 time.sleep(0.5)
1617 x = ['a' * i for i in range(100)]
@@ -19,21 +20,64 @@ def test_ok():
1920""" )
2021
2122 # run pytest with the following cmd args
22- result = testdir .runpytest ('-v ' )
23+ result = testdir .runpytest ('-vv' , '--tag' , 'version=12.3.5 ' )
2324
2425 # fnmatch_lines does an assertion internally
2526 result .stdout .fnmatch_lines (['*::test_ok PASSED*' ])
2627
2728 pymon_path = pathlib .Path (str (testdir )) / '.pymon'
2829 assert pymon_path .exists ()
2930
30- # make sure that that we get a '0' exit code for the testsuite
31+ # make sure that that we get a '0' exit code for the test suite
3132 result .assert_outcomes (passed = 1 )
3233
3334 db = sqlite3 .connect (str (pymon_path ))
3435 cursor = db .cursor ()
3536 cursor .execute ('SELECT ITEM FROM TEST_METRICS;' )
3637 assert 1 == len (cursor .fetchall ()) # current test
38+ cursor = db .cursor ()
39+ tags = json .loads (cursor .execute ('SELECT RUN_DESCRIPTION FROM TEST_SESSIONS;' ).fetchone ()[0 ])
40+ assert 'description' not in tags
41+ assert 'version' in tags
42+ assert tags ['version' ] == "12.3.5"
43+
44+
45+ def test_monitor_basic_test_description (testdir ):
46+ """Make sure that pytest-monitor does the job without impacting user tests."""
47+ # create a temporary pytest test module
48+ testdir .makepyfile ("""
49+ import time
50+
51+
52+ def test_ok():
53+ time.sleep(0.5)
54+ x = ['a' * i for i in range(100)]
55+ assert len(x) == 100
56+
57+ """ )
58+
59+ # run pytest with the following cmd args
60+ result = testdir .runpytest ('-vv' , '--description' , '"Test"' , '--tag' , 'version=12.3.5' )
61+
62+ # fnmatch_lines does an assertion internally
63+ result .stdout .fnmatch_lines (['*::test_ok PASSED*' ])
64+
65+ pymon_path = pathlib .Path (str (testdir )) / '.pymon'
66+ assert pymon_path .exists ()
67+
68+ # make sure that that we get a '0' exit code for the test suite
69+ result .assert_outcomes (passed = 1 )
70+
71+ db = sqlite3 .connect (str (pymon_path ))
72+ cursor = db .cursor ()
73+ cursor .execute ('SELECT ITEM FROM TEST_METRICS;' )
74+ assert 1 == len (cursor .fetchall ()) # current test
75+ cursor = db .cursor ()
76+ tags = json .loads (cursor .execute ('SELECT RUN_DESCRIPTION FROM TEST_SESSIONS;' ).fetchone ()[0 ])
77+ assert 'description' in tags
78+ assert tags ['description' ] == '"Test"'
79+ assert 'version' in tags
80+ assert tags ['version' ] == "12.3.5"
3781
3882
3983def test_monitor_pytest_skip_marker (testdir ):
0 commit comments