summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/test/local_test_server.cc4
-rw-r--r--net/test/python_utils.cc8
-rw-r--r--net/test/python_utils.h8
3 files changed, 20 insertions, 0 deletions
diff --git a/net/test/local_test_server.cc b/net/test/local_test_server.cc
index af94a50..8bddbc3a 100644
--- a/net/test/local_test_server.cc
+++ b/net/test/local_test_server.cc
@@ -105,6 +105,10 @@ bool LocalTestServer::Start() {
if (!SetPythonPath())
return false;
+ // Ensures that python testserver output, if any, will not clash with
+ // post-test gtest output.
+ EnablePythonUnbufferedMode();
+
if (!LaunchPython(testserver_path))
return false;
diff --git a/net/test/python_utils.cc b/net/test/python_utils.cc
index 0eec816..7e0e79a 100644
--- a/net/test/python_utils.cc
+++ b/net/test/python_utils.cc
@@ -14,6 +14,7 @@
#include "base/utf_string_conversions.h"
const char kPythonPathEnv[] = "PYTHONPATH";
+const char kPythonUnbufferedEnv[] = "PYTHONUNBUFFERED";
void AppendToPythonPath(const FilePath& dir) {
scoped_ptr<base::Environment> env(base::Environment::Create());
@@ -115,3 +116,10 @@ bool GetPythonRunTime(FilePath* dir) {
#endif
return true;
}
+
+void EnablePythonUnbufferedMode() {
+ // Python output will be unbuffered if kPythonUnbufferedEnv is set to any
+ // non-empty string.
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->SetVar(kPythonUnbufferedEnv, "true");
+}
diff --git a/net/test/python_utils.h b/net/test/python_utils.h
index 583fb27..377a3ec 100644
--- a/net/test/python_utils.h
+++ b/net/test/python_utils.h
@@ -12,6 +12,9 @@ class FilePath;
// This is the python path variable name.
extern const char kPythonPathEnv[];
+// This is the python unbuffered variable name.
+extern const char kPythonUnbufferedEnv[];
+
// Appends the dir to python path environment variable.
void AppendToPythonPath(const FilePath& dir);
@@ -21,4 +24,9 @@ bool GetPyProtoPath(FilePath* dir);
// Returns the path that should be used to launch Python.
bool GetPythonRunTime(FilePath* path) WARN_UNUSED_RESULT;
+// Sets the environment variable that forces python console output to be
+// unbuffered. Used so that buffered logs don't interfere with gtest logs after
+// a test has been run.
+void EnablePythonUnbufferedMode();
+
#endif // NET_TEST_PYTHON_UTILS_H_