Repository: blake-r/pytest-durations (language: python)

Issue:
Little test improvements
Little test improvements:

- make coverage 100%
- use importlib.reload in test_freezegun_import_error
- use _SAMPLE_SECTION_NAME in test_report_measurements_empty_results


Discussion / hints:

Fix patch:
diff --git a/.coveragerc b/.coveragerc
index 94a6efd..bbdda94 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -16,3 +16,4 @@ omit =
 show_missing = true
 skip_covered = true
 skip_empty = true
+fail_under = 100


Test patch:
diff --git a/tests/test_options.py b/tests/test_options.py
new file mode 100644
index 0000000..3f23481
--- /dev/null
+++ b/tests/test_options.py
@@ -0,0 +1,45 @@
+import importlib
+import sys
+from unittest.mock import create_autospec
+
+import pytest
+
+from pytest_durations.options import pytest_addoption, pytest_configure
+
+
+@pytest.fixture(autouse=True, scope="module")
+def reload_module():
+    # Reloading is required for proper code coverage detection
+    importlib.reload(sys.modules["pytest_durations.options"])
+
+
+@pytest.fixture
+def fake_parser():
+    return create_autospec(pytest.Parser, instance=True)
+
+
+@pytest.fixture
+def fake_pluginmanager():
+    return create_autospec(pytest.PytestPluginManager, instance=True)
+
+
+@pytest.fixture
+def fake_config(fake_pluginmanager):
+    return create_autospec(pytest.Config, instance=True, pluginmanager=fake_pluginmanager)
+
+
+def test_pytest_addoption(fake_parser, fake_pluginmanager):
+    pytest_addoption(fake_parser, fake_pluginmanager)
+    assert fake_parser.getgroup.called is True
+    assert fake_parser.getgroup.return_value.addoption.call_count == 2
+
+
+def test_pytest_configure(fake_config, fake_pluginmanager):
+    pytest_configure(fake_config)
+    assert fake_pluginmanager.register.called is True
+
+
+def test_pytest_configure_disabled(fake_config, fake_pluginmanager):
+    fake_config.getoption.return_value = None
+    pytest_configure(fake_config)
+    assert fake_pluginmanager.register.called is False
diff --git a/tests/test_reporting.py b/tests/test_reporting.py
index 0b06483..0ed2838 100644
--- a/tests/test_reporting.py
+++ b/tests/test_reporting.py
@@ -4,8 +4,6 @@
 
 from pytest_durations.reporting import get_report_rows, get_report_max_widths
 
-_SAMPLE_SECTION_NAME = "sample section"
-
 
 @pytest.fixture
 def sample_measurements() -> Dict[str, List[float]]:
diff --git a/tests/test_xdist.py b/tests/test_xdist.py
new file mode 100644
index 0000000..82d762b
--- /dev/null
+++ b/tests/test_xdist.py
@@ -0,0 +1,52 @@
+from unittest.mock import Mock, create_autospec
+
+import pytest
+import xdist.workermanage
+
+from pytest_durations.plugin import Category
+from pytest_durations.xdist import PytestDurationXdistMixin
+
+
+@pytest.fixture
+def fake_session():
+    return create_autospec(pytest.Session, instance=True)
+
+
+@pytest.fixture
+def fake_node():
+    return create_autospec(xdist.workermanage.WorkerController, instance=True)
+
+
+@pytest.fixture
+def instance(measurements):
+    instance = PytestDurationXdistMixin()
+    instance.measurements = {Category.TEST_CALL: {}}
+    return instance
+
+
+@pytest.fixture
+def measurements():
+    return {Category.TEST_CALL: {"fixture1": [0.1, 0.2, 0.3]}}
+
+
+def test_pytest_sessionfinish(fake_session, instance, measurements):
+    instance.measurements = measurements
+    fake_session.config.workeroutput = {}
+    instance.pytest_sessionfinish(fake_session, 0)
+    assert fake_session.config.workeroutput == {"pytest_durations": measurements}
+
+
+def test_pytest_sessionfinish_noxdist(fake_session, instance, measurements):
+    instance.pytest_sessionfinish(fake_session, 0)
+    assert isinstance(fake_session.config.workeroutput["pytest_durations"], Mock)
+
+
+def test_pytest_testnodedown(fake_node, instance, measurements):
+    fake_node.workeroutput = {"pytest_durations": measurements}
+    instance.pytest_testnodedown(fake_node, None)
+    assert instance.measurements == measurements
+
+
+def test_pytest_testnodedown_noxdist(fake_node, instance, measurements):
+    instance.pytest_testnodedown(fake_node, None)
+    assert instance.measurements == {"test": {}}