Repository: theacodes/nox (python)

Issue:
Nox is no longer executing sessions in the order specified on the command line

Pull request description:
Run sessions in the same order specified on the command line.
Closes #150

Patch:
diff --git a/nox/manifest.py b/nox/manifest.py
index 2b87314..534367c 100644
--- a/nox/manifest.py
+++ b/nox/manifest.py
@@ -118,12 +118,15 @@ class Manifest:
         """
         # Filter the sessions remaining in the queue based on
         # whether they are individually specified.
-        specified_sessions = set(specified_sessions)
-        self._queue = [
-            x
-            for x in self._queue
-            if (x.name in specified_sessions or set(x.signatures) & specified_sessions)
-        ]
+        queue = []
+        for session_name in specified_sessions:
+            for session in self._queue:
+                if session_name == session.name or session_name in set(
+                    session.signatures
+                ):
+                    queue.append(session)
+
+        self._queue = queue
 
         # If a session was requested and was not found, complain loudly.
         all_sessions = set(
@@ -132,7 +135,7 @@ class Manifest:
                 *[x.signatures for x in self._all_sessions],
             )
         )
-        missing_sessions = specified_sessions - all_sessions
+        missing_sessions = set(specified_sessions) - all_sessions
         if missing_sessions:
             raise KeyError("Sessions not found: {}".format(", ".join(missing_sessions)))
 


Test patch:
diff --git a/tests/test_manifest.py b/tests/test_manifest.py
index e94eb97..d679e8f 100644
--- a/tests/test_manifest.py
+++ b/tests/test_manifest.py
@@ -124,6 +124,13 @@ def test_filter_by_name():
     assert "bar" not in manifest
 
 
+def test_filter_by_name_maintains_order():
+    sessions = create_mock_sessions()
+    manifest = Manifest(sessions, mock.sentinel.CONFIG)
+    manifest.filter_by_name(("bar", "foo"))
+    assert [session.name for session in manifest] == ["bar", "foo"]
+
+
 def test_filter_by_name_not_found():
     sessions = create_mock_sessions()
     manifest = Manifest(sessions, mock.sentinel.CONFIG)