1515import os
1616
1717import pytest
18- from invoke .context import Context
1918import simplejson as json
19+ from invoke import Local
20+ from invoke .context import Context
2021
2122from .common import Board
2223
@@ -57,7 +58,7 @@ def run_command(pytestconfig, data_dir, downloads_dir, working_dir):
5758 will work in the same temporary folder.
5859
5960 Useful reference:
60- http://docs.pyinvoke.org/en/1.2 /api/runners.html#invoke.runners.Result
61+ http://docs.pyinvoke.org/en/1.4 /api/runners.html#invoke.runners.Result
6162 """
6263 cli_path = os .path .join (str (pytestconfig .rootdir ), ".." , "arduino-cli" )
6364 env = {
@@ -67,7 +68,7 @@ def run_command(pytestconfig, data_dir, downloads_dir, working_dir):
6768 }
6869 os .makedirs (os .path .join (data_dir , "packages" ))
6970
70- def _run (cmd_string ):
71+ def _run (cmd_string , asynchronous = False ):
7172 cli_full_line = "{} {}" .format (cli_path , cmd_string )
7273 run_context = Context ()
7374 with run_context .cd (working_dir ):
@@ -78,6 +79,35 @@ def _run(cmd_string):
7879 return _run
7980
8081
82+ @pytest .fixture (scope = "function" )
83+ def daemon_runner (pytestconfig , data_dir , downloads_dir , working_dir ):
84+ """
85+ Provide an invoke's `Local` object that has started the arduino-cli in daemon mode.
86+ This way is simple to start and kill the daemon when the test is finished
87+ via the kill() function
88+
89+ Useful reference:
90+ http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Local
91+ http://docs.pyinvoke.org/en/1.4/api/runners.html
92+ """
93+ cli_full_line = os .path .join (str (pytestconfig .rootdir ), ".." , "arduino-cli daemon" )
94+ env = {
95+ "ARDUINO_DATA_DIR" : data_dir ,
96+ "ARDUINO_DOWNLOADS_DIR" : downloads_dir ,
97+ "ARDUINO_SKETCHBOOK_DIR" : data_dir ,
98+ }
99+ os .makedirs (os .path .join (data_dir , "packages" ))
100+ run_context = Context ()
101+ run_context .cd (working_dir )
102+ # Local Class is the implementation of a Runner abstract class
103+ runner = Local (run_context )
104+ runner .run (
105+ cli_full_line , echo = False , hide = True , warn = True , env = env , asynchronous = True
106+ )
107+
108+ return runner
109+
110+
81111@pytest .fixture (scope = "function" )
82112def detected_boards (run_command ):
83113 """
0 commit comments