Skip to content

Commit 3a7ca36

Browse files
authored
#24 - Use json for storing data instead of text
1 parent e1f8a2a commit 3a7ca36

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

docs/sources/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog
33
=========
44

5+
* :release:`1.6.0 <2021-04-16>`
6+
* :feature:`#0` Support for python 3.5
7+
* :feature:`#35` Better support for Doctest item.
8+
* :feature:`#24` Prefer JSON data type for storing session extended information instead of plain text.
9+
10+
511
* :release:`1.5.1 <2021-02-05>`
612
* :bug:`#31` Rename option --remote into --remote-server as it seems to conflict with some plugins.
713
* :bug:`#23` Fix requirements minimum version.

pytest_monitor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "1.5.1"
1+
__version__ = "1.6.0"
22
__author__ = "Jean-Sebastien Dieu"

pytest_monitor/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def prepare(self):
4646
SESSION_H varchar(64) primary key not null unique, -- Session identifier
4747
RUN_DATE varchar(64), -- Date of test run
4848
SCM_ID varchar(128), -- SCM change id
49-
RUN_DESCRIPTION varchar(1024)
49+
RUN_DESCRIPTION json
5050
);''')
5151
cursor.execute('''
5252
CREATE TABLE IF NOT EXISTS TEST_METRICS (

tests/test_monitor.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import json
23
import pathlib
34
import pytest
45
import 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

3983
def test_monitor_pytest_skip_marker(testdir):

0 commit comments

Comments
 (0)