Repository: scoutapp/scout_apm_python

Issue:
Don't attempt to start on Windows (until supported)
As of right now, we error out when attempting to start on a Microsoft Windows system.

We should detect that the OS is not supported, and not start at all (and log that fact).


Discussion:

Patch:
diff --git a/src/scout_apm/core/__init__.py b/src/scout_apm/core/__init__.py
index 58c1323..0de41b9 100644
--- a/src/scout_apm/core/__init__.py
+++ b/src/scout_apm/core/__init__.py
@@ -2,6 +2,7 @@
 from __future__ import absolute_import, division, print_function, unicode_literals
 
 import logging
+import sys
 from os import getpid
 
 from scout_apm.core.config import ScoutConfig
@@ -23,6 +24,10 @@ def install(*args, **kwargs):
         ScoutConfig().set(**kwargs["config"])
     context = AgentContext.build(config=ScoutConfig())
 
+    if sys.platform == "win32":
+        logger.info("APM Not Launching on PID: %s - Windows is not supported", getpid())
+        return False
+
     if not context.config.value("monitor"):
         logger.info(
             "APM Not Launching on PID: %s - Configuration 'monitor' is not true",


Test patch:
diff --git a/tests/unit/test_core.py b/tests/unit/test_core.py
new file mode 100644
index 0000000..bcfe54b
--- /dev/null
+++ b/tests/unit/test_core.py
@@ -0,0 +1,55 @@
+# coding=utf-8
+from __future__ import absolute_import, division, print_function, unicode_literals
+
+import logging
+import os
+import sys
+
+from scout_apm.api import Config
+from scout_apm.core import install
+from scout_apm.core.core_agent_manager import CoreAgentManager
+from tests.compat import mock
+
+
+def test_install_fail_windows(caplog):
+    with mock.patch.object(sys, "platform", new="win32"):
+        installed = install()
+
+    assert installed is False
+    assert (
+        "scout_apm.core",
+        logging.INFO,
+        "APM Not Launching on PID: %s - Windows is not supported" % os.getpid(),
+    ) in caplog.record_tuples
+
+
+def test_install_fail_monitor_false(caplog):
+    try:
+        installed = install(config={"monitor": False})
+    finally:
+        Config.reset_all()
+
+    assert installed is False
+    assert (
+        "scout_apm.core",
+        logging.INFO,
+        (
+            "APM Not Launching on PID: %s - Configuration 'monitor' is not true"
+            % os.getpid()
+        ),
+    ) in caplog.record_tuples
+
+
+def test_install_success(caplog):
+    with mock.patch.object(CoreAgentManager, "launch"):
+        try:
+            installed = install(config={"monitor": True})
+        finally:
+            Config.reset_all()
+
+    assert installed is True
+    assert (
+        "scout_apm.core",
+        logging.DEBUG,
+        "APM Launching on PID: %s" % os.getpid(),
+    ) in caplog.record_tuples