Hello Dustin,
Thank you for your response and the link to the PyFrcPlugin location.
I agree that it would be cool to have Unit Testing work in VS Code. It seems like there needs to be a way to feed the pytest_plugin.PyFrcPlugin location to PyTest when it is being started by the Test Explorer, and make sure that PyTest accesses the fixtures needed.
retv = pytest.main( pytest_args,
plugins=[ pytest_plugin.PyFrcPlugin(robot_class, robot_file, robot_path) ], )
- control - the wpilib.internal module
-
fake_time - the FAKETIME object that controls time
-
robot - This is whatever is returned from the run function in robot.py
-
robot_file - The filename of robot.py
-
robot_path - The directory name that robot.py is located in
-
wpilib - This is the wpilib module
I am not certain yet what is required to be configured in VS Code to get this setup to run outside of the main.py and PyFrcTest class methods.
âmain.pyâ appears to setup the variables for the robot_class, the PyTest arguments, and has the references to the classes needed, which may not be imported in the Unit Test classes (if the example tests are followed).
It would be nice to be able to call pytest from the command line and run the unit test file, but it is failing for me.
It also seems like main.py is not passing along any additional arguments entered after âtestâ when calling âpy -3 robot.py testâ, but there is framework for it. It may be nice to feed the pytest module call with additional pytest arguments ; âmain.pyâ may need to be modified for this to happen, allowing arguments to pass through to the pytest.main() method call. I am thinking of commands along the lines of:
py -3 -m pytest -v robot_test.py -p pytest_plugin
py -3 robot.py test -v --fixtures --version
py -3 robot.py test -v --maxfail=2 TestDirectory/
py -3 robot.py test -rA test_mod.py
py -3 robot.py test -v -k âMyClass and not methodâ
May need to use âPythonPath/Lib/site-packages/pyfrc/mains/cli_test.pyâ in the argument to get to the FRC plugin.
It also might be nice to have it drop to the Debugger if it fails a test
pytest -x --pdb
py -3 robot.py test -x --pdb
Debugger
I was able to get the debugger to run with the automated tests by adding some commands to the Workspace launch.json file in the.vscode directory. I added âtestâ for the âargsâ key in the âconfigurationsâ dictionary to get the unit tests to run in the debugger, and I set the KVP âjustMyCodeâ to false to get the debugger to run in the WPIlib class files.
I also was able to launch the simulator from the debugger by using a âargsâ: [âsimâ] KVP. I have the âprogramâ key set to the current file, so the ârobot.pyâ file has to be open and selected for the debugger to launch correctly. It can also work by hard coding the path to the robot.py file instead of using â${file}â.
It is basically calling
cd âMyPath\Sethâ; ${env:PYTHONIOENCODING}=âUTF-8â; ${env:PYTHONUNBUFFERED}=â1â; & âPYTHONPath\python.exeâ 'VSCodePath.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.pyâ ââdefaultâ ââclientâ ââhostâ âlocalhostâ ââportâ â56841â âSourceCodePath\robot.pyâ âtestâ
to launch the debugger with the equivalent of the command âpy -3 robot.py testâ .
This has allowed me to do debugging in the unit tests to find out what is happening when an assert fails. It does not have the nice presentation that Test Explorer has, and the functionality to pick and choose a subset of tests; it runs through all tests discovered (that adhere to the directory and filename patterns).