File tree 4 files changed +53
-2
lines changed
4 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 2
2
Changelog
3
3
=========
4
4
5
+ * :release: `1.6.4 <2022-05-18> `
6
+ * :bug: `#56 ` Force the CPU frequency to 0 and emit a warning when unable to fetch it from the system.
7
+ * :bug: `#54 ` Fix a bug that crashes the monitor upon non ASCII characters in commit log under Perforce. Improved P4 change number extraction.
8
+
5
9
* :release: `1.6.3 <2021-12-22> `
6
10
* :bug: `#50 ` Fix a bug where a skipping fixture resulted in an exception during teardown.
7
11
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ session. An Execution Context describes much of the machine settings:
58
58
CPU_COUNT (integer)
59
59
Number of online CPUs the machine can use.
60
60
CPU_FREQUENCY_MHZ (integer)
61
- Base frequency of the CPUs (in megahertz).
61
+ Base frequency of the CPUs (in megahertz). Set to 0 if unable to fetch it.
62
62
CPU_VENDOR (TEXT 256 CHAR)
63
63
Full CPU vendor string.
64
64
RAM_TOTAL_MB (INTEGER)
Original file line number Diff line number Diff line change 6
6
import socket
7
7
import subprocess
8
8
import sys
9
+ import warnings
9
10
10
11
11
12
def collect_ci_info ():
@@ -67,7 +68,11 @@ class ExecutionContext:
67
68
def __init__ (self ):
68
69
self .__cpu_count = multiprocessing .cpu_count ()
69
70
self .__cpu_vendor = _get_cpu_string ()
70
- self .__cpu_freq_base = psutil .cpu_freq ().current
71
+ try :
72
+ self .__cpu_freq_base = psutil .cpu_freq ().current
73
+ except AttributeError :
74
+ warnings .warn ("Unable to fetch CPU frequency. Forcing it to 0." )
75
+ self .__cpu_freq_base = 0
71
76
self .__proc_typ = platform .processor ()
72
77
self .__tot_mem = int (psutil .virtual_memory ().total / 1024 ** 2 )
73
78
self .__fqdn = socket .getfqdn ()
Original file line number Diff line number Diff line change
1
+ import mock
2
+ import pathlib
3
+ import sqlite3
4
+
5
+
6
+ @mock .patch ('pytest_monitor.sys_utils.psutil.cpu_freq' , return_value = None )
7
+ def test_when_cpu_freq_cannot_fetch_frequency (cpu_freq_mock , testdir ):
8
+ """Make sure that pytest-monitor does the job when we have issue in collecing context resources"""
9
+ # create a temporary pytest test module
10
+ testdir .makepyfile ("""
11
+ import time
12
+
13
+
14
+ def test_ok():
15
+ time.sleep(0.5)
16
+ x = ['a' * i for i in range(100)]
17
+ assert len(x) == 100
18
+
19
+ """ )
20
+
21
+ # run pytest with the following cmd args
22
+ result = testdir .runpytest ('-vv' )
23
+
24
+ # fnmatch_lines does an assertion internally
25
+ result .stdout .fnmatch_lines (['*::test_ok PASSED*' ])
26
+
27
+ pymon_path = pathlib .Path (str (testdir )) / '.pymon'
28
+ assert pymon_path .exists ()
29
+
30
+ # make sure that that we get a '0' exit code for the test suite
31
+ result .assert_outcomes (passed = 1 )
32
+
33
+ db = sqlite3 .connect (str (pymon_path ))
34
+ cursor = db .cursor ()
35
+ cursor .execute ('SELECT ITEM FROM TEST_METRICS;' )
36
+ assert 1 == len (cursor .fetchall ()) # current test
37
+ cursor = db .cursor ()
38
+ cursor .execute ('SELECT CPU_FREQUENCY_MHZ FROM EXECUTION_CONTEXTS;' )
39
+ rows = cursor .fetchall ()
40
+ assert 1 == len (rows )
41
+ assert rows [0 ][0 ] == 0
42
+
You can’t perform that action at this time.
0 commit comments