Skip to content

Commit

Permalink
Change default analysis scope (#16)
Browse files Browse the repository at this point in the history
* PM #13 - Set function as default analysis scope. Docs updated accordingly
  • Loading branch information
js-dieu committed Apr 17, 2020
1 parent 9d0a897 commit 3c61280
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/sources/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Changelog
=========

* :release:`1.2.0 <2020-04-17>`
* :feature:`13` Change default analysis scope to function.

* :release:`1.1.1 <2020-03-31>`
* :bug:`9` Fix remote server interface for sending measures.

Expand Down
2 changes: 1 addition & 1 deletion docs/sources/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Scope Restriction
-----------------

`pytest-monitor` is able to restrict the scope of the analysis. As a default,
any test object discovered by pytest is monitored (test functions and test classes).
only tests functions discovered by pytest are monitored.

Sometime, you might want to monitor a whole module or test session. This can be
achieved thanks to the *\-\-restrict-scope-to* option.
Expand Down
2 changes: 1 addition & 1 deletion pytest_monitor/pytest_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def pytest_addoption(parser):
group = parser.getgroup('monitor')
group.addoption('--restrict-scope-to', dest='mtr_scope', default='function,module',
group.addoption('--restrict-scope-to', dest='mtr_scope', default='function',
help='Select the scope to monitor. By default, only function is monitored.'
'Values are function, class, module, session. You can set one or more of these'
'by listing them using a comma separated list')
Expand Down
11 changes: 6 additions & 5 deletions tests/test_monitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import pathlib
import pytest
import sqlite3


Expand Down Expand Up @@ -32,7 +33,7 @@ def test_ok():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 2 == len(cursor.fetchall()) # current test + test_ok
assert 1 == len(cursor.fetchall()) # current test


def test_monitor_pytest_skip_marker(testdir):
Expand Down Expand Up @@ -99,7 +100,7 @@ def test_ok():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 2 == len(cursor.fetchall()) # current test + test_ok
assert 1 == len(cursor.fetchall()) # current test


def test_monitor_skip_module(testdir):
Expand Down Expand Up @@ -136,7 +137,7 @@ def test_another_function_ok_not_monitored():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 1 == len(cursor.fetchall()) # current test + test_ok
assert not len(cursor.fetchall()) # Nothing ran


def test_monitor_skip_test(testdir):
Expand Down Expand Up @@ -170,7 +171,7 @@ def test_not_monitored():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 1 == len(cursor.fetchall()) # current test + test_ok
assert not len(cursor.fetchall()) # nothing monitored


def test_monitor_skip_test_if(testdir):
Expand Down Expand Up @@ -213,4 +214,4 @@ def test_monitored():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 2 == len(cursor.fetchall()) # current test + test_monitored
assert 1 == len(cursor.fetchall())
12 changes: 6 additions & 6 deletions tests/test_monitor_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_ok():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 2 == len(cursor.fetchall()) # current test + test_ok
assert 1 == len(cursor.fetchall())
cursor.execute("SELECT ITEM FROM TEST_METRICS WHERE COMPONENT != '' AND ITEM LIKE '%test_ok';")
assert not len(cursor.fetchall())

Expand All @@ -55,7 +55,7 @@ def test_force_ok():
""")

# run pytest with the following cmd args
result = testdir.runpytest('--force-component','my_component', '-v')
result = testdir.runpytest('--force-component', 'my_component', '-v')

# fnmatch_lines does an assertion internally
result.stdout.fnmatch_lines(['*::test_force_ok PASSED*'])
Expand All @@ -69,7 +69,7 @@ def test_force_ok():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 2 == len(cursor.fetchall()) # current test + test_ok
assert 1 == len(cursor.fetchall())
cursor.execute("SELECT ITEM FROM TEST_METRICS"
" WHERE COMPONENT == 'my_component' AND ITEM LIKE '%test_force_ok%';")
assert 1 == len(cursor.fetchall())
Expand Down Expand Up @@ -106,10 +106,10 @@ def test_prefix_ok():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 2 == len(cursor.fetchall()) # current test + test_ok
assert 1 == len(cursor.fetchall())
cursor.execute("SELECT ITEM FROM TEST_METRICS"
" WHERE COMPONENT == 'my_component' AND ITEM LIKE '%test_prefix_ok%';")
assert 0 == len(cursor.fetchall())
assert not len(cursor.fetchall())
cursor.execute("SELECT ITEM FROM TEST_METRICS"
" WHERE COMPONENT == 'my_component.internal' AND ITEM LIKE '%test_prefix_ok%';")
assert 1 == len(cursor.fetchall())
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_prefix_ok():
db = sqlite3.connect(str(pymon_path))
cursor = db.cursor()
cursor.execute('SELECT ITEM FROM TEST_METRICS;')
assert 2 == len(cursor.fetchall()) # current test + test_ok
assert 1 == len(cursor.fetchall())
cursor.execute("SELECT ITEM FROM TEST_METRICS"
" WHERE COMPONENT == 'my_component' AND ITEM LIKE '%test_prefix_ok%';")
assert 1 == len(cursor.fetchall())

0 comments on commit 3c61280

Please sign in to comment.