It’s your dist/work/spec path parameters causing the problem. They need to be written as either '--distpath=B:\\coding\\py2exe' or two separate strings '--distpath', 'B:\\coding\\py2exe'. The command line equivalent of your current Python code is
pyinstaller --onefile --clean "--distpath B:\coding\py2exe" "--workpath B:\coding\py2exe\temp_build_folder" "--specpath B:\\coding\\py2exe\\temp_spec_folder" --noconfirm -c B:/coding/py2exe/test.pywhich is not valid.