{"id":7348,"date":"2019-08-13T15:41:38","date_gmt":"2019-08-13T23:41:38","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/python\/?p=7348"},"modified":"2019-11-18T22:03:41","modified_gmt":"2019-11-19T06:03:41","slug":"whats-new-for-python-in-visual-studio-16-3-preview-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/python\/whats-new-for-python-in-visual-studio-16-3-preview-2\/","title":{"rendered":"What&#8217;s New for Python in Visual Studio (16.3 Preview 2)"},"content":{"rendered":"<p style=\"text-align: left;\"><span data-contrast=\"auto\">Today, we are releasing Visual Studio 2019<\/span><span data-contrast=\"auto\">\u00a0(16.3 Preview 2<\/span><span data-contrast=\"auto\">)<\/span><span data-contrast=\"auto\">, which contains an\u00a0<\/span><span data-contrast=\"auto\">updated<\/span><span data-contrast=\"auto\">\u00a0test<\/span><span data-contrast=\"auto\">ing\u00a0<\/span><span data-contrast=\"auto\">experience for Python\u00a0<\/span><span data-contrast=\"auto\">developers<\/span><span data-contrast=\"auto\">.\u00a0<\/span><span data-contrast=\"auto\">We are happy to announce that t<\/span><span data-contrast=\"auto\">he popular Python testing\u00a0<\/span><span data-contrast=\"auto\">framework<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">p<\/span><span data-contrast=\"auto\">ytest<\/span><span data-contrast=\"auto\">\u00a0is now supported<\/span><span data-contrast=\"auto\">. Additionally, we have re-worked the unittest experience for Python users<\/span><span data-contrast=\"auto\">\u00a0in\u00a0<\/span><span data-contrast=\"auto\">this release.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p style=\"text-align: left;\"><span data-contrast=\"auto\">Continue reading to learn more about how you can enable and configure\u00a0<\/span><span data-contrast=\"auto\">pytest<\/span><span data-contrast=\"auto\">\u00a0and\/or unittest for your development environment.\u00a0<\/span><span data-contrast=\"auto\">What\u2019s even\u00a0<\/span><span data-contrast=\"auto\">better is<\/span><span data-contrast=\"auto\">\u00a0that\u00a0<\/span><span data-contrast=\"auto\">each testing framework<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">is<\/span><span data-contrast=\"auto\">\u00a0supported\u00a0<\/span><span data-contrast=\"auto\">in<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-contrast=\"auto\">both\u00a0<\/span><span data-contrast=\"auto\">project mode<\/span><span data-contrast=\"auto\">\u00a0and\u00a0<\/span><span data-contrast=\"auto\">in\u00a0<\/span><span data-contrast=\"auto\">O<\/span><span data-contrast=\"auto\">pen\u00a0<\/span><span data-contrast=\"auto\">F<\/span><span data-contrast=\"auto\">older scenarios.\u00a0<\/span><span data-contrast=\"auto\">\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2>Enabling and Configuring Testing for Projects<\/h2>\n<p style=\"text-align: left;\">Configuring and working with Python tests in Visual Studio is easier than ever before.<\/p>\n<p>\u00a0For users who are new to the testing experience within Visual Studio 2019 for Python projects, right-click on the project name and select the \u2018Properties\u2019 option. This option opens the project designer, which allows you to configure tests by going to the \u2018Test\u2019 tab.<\/p>\n<p style=\"text-align: left;\">From this tab, simply click the \u2019Test Framework\u2019 dropdown box to select the testing framework you wish to use:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-7352\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/newtestingfeatures_blog.gif\" alt=\"Walkthrough of New Testing Features in VS2019 16.3\" width=\"1417\" height=\"742\" \/><\/p>\n<ul>\n<li style=\"text-align: left;\">For <strong>unittest<\/strong>, we use the project\u2019s root directory for test discovery. This is a default setting that can be modified to include the path to the folder that contains your tests (if your tests are included in a sub-directory). We also use the unittest framework\u2019s default pattern for test filenames (this also can be modified if you use a different file naming system for your test files). Prior to this release, unittest discovery was automatically initiated for the user. Now, the user is required to manually configure testing.<\/li>\n<li style=\"text-align: left;\">For <strong>pytest<\/strong>, you can specify a .ini configuration file which contains test filename patterns in addition to many other testing options.<\/li>\n<\/ul>\n<p>Once you select and save your changes in the window, test discovery is initiated in the Test Explorer. If the Test Explorer is not open, navigate to the Toolbar and select <strong>Test &gt; Windows &gt; Test Explorer<\/strong>. Test Discovery can take up to 60 seconds, after which the test discovery process will end.<\/p>\n<p>Once in the Test Explorer window, you have the ability to re-run your tests (by clicking the \u2018Run All\u2019 button or pressing <strong>CTRL + R,A<\/strong>) as well as view the status of your test runs. \u00a0Additionally, you can see the total number of tests your project contains and the duration of test runs:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-7353\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/TestExplorer.png\" alt=\"to show the status of test runs in VS\" width=\"283\" height=\"314\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/TestExplorer.png 283w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/TestExplorer-270x300.png 270w\" sizes=\"(max-width: 283px) 100vw, 283px\" \/><\/p>\n<p>If you wish to keep working while tests are running in the background but want to monitor the progress of your test run, you can go to the Output window and choose \u2018Show output from: Tests\u2019:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-7355\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/outputwindow-1.png\" alt=\"show the user how to select the tests output\" width=\"1222\" height=\"273\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/outputwindow-1.png 1222w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/outputwindow-1-300x67.png 300w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/outputwindow-1-768x172.png 768w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/outputwindow-1-1024x229.png 1024w\" sizes=\"(max-width: 1222px) 100vw, 1222px\" \/><\/p>\n<p>We have also made it simple for users with pre-existing projects that contain test files to quickly continue working with their code in Visual Studio 2019. When you open a project that contains testing configuration files (e.g. a .ini file for pytest), but you have not installed or enabled pytest, you will be prompted to install the necessary packages and configure them for the Python environment in which you are working:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-7356 size-full\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/pytest_infobar.png\" alt=\"install and enable pytest infobar\" width=\"1113\" height=\"36\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/pytest_infobar.png 1113w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/pytest_infobar-300x10.png 300w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/pytest_infobar-768x25.png 768w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/pytest_infobar-1024x33.png 1024w\" sizes=\"(max-width: 1113px) 100vw, 1113px\" \/><\/p>\n<p>For open folder scenarios (described below), these informational bars will also be triggered if you have not configured your workspace for pytest or unittest.<\/p>\n<p>&nbsp;<\/p>\n<h2>Configuring Tests for Open Folder Scenarios<\/h2>\n<p>In this release of Visual Studio 2019, users can configure tests to work in our popular open folder scenario.<\/p>\n<p>To configure and enable tests, navigate to the Solution explorer, click the \u201cShow All Files\u201d icon to show all files in the current folder and select the PythonSettings.json file within the \u2018Local Settings\u2019 folder. (If this file doesn\u2019t exist, create one in \u2018Local Settings\u2019 folder). Next, add the field <span style=\"color: #0000ff;\">TestFramework<\/span>: <span style=\"color: #993300;\">&#8220;pytest&#8221;<\/span>\u00a0to your settings file or <span style=\"color: #0000ff;\">TestFramework<\/span>: <span style=\"color: #993300;\">&#8220;unittest&#8221;<\/span>\u00a0depending on the testing framework you wish to use.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-7357 size-full\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/settingsjsonfortests.png\" alt=\"json settings file for tests\" width=\"703\" height=\"144\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/settingsjsonfortests.png 703w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/settingsjsonfortests-300x61.png 300w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>For the unittest framework, If <span style=\"color: #0000ff;\">UnitTestRootDirectory<\/span> and\/or <span style=\"color: #0000ff;\">UnitTestPattern<\/span> are not specified in PythonSettings.json, they are added and assigned default values of <span style=\"color: #993300;\">\u201c.\u201d<\/span> and <span style=\"color: #993300;\">\u201ctest*.py\u201d<\/span>, respectively.<\/p>\n<p>As in project mode, editing and saving any file triggers test discovery for the test framework that you specified. If you already have the Test Explorer window open, clicking <strong>CTRL + R,A <\/strong>also triggers discovery.<\/p>\n<p><em>Note: If your folder contains a \u2018src\u2019 directory which is separate from the folder that contains your tests, you\u2019ll need to specify the path to the src folder in your PythonSettings.json with the setting <\/em><span style=\"color: #0000ff;\">SearchPaths<span style=\"color: #000000;\">:<\/span><\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-7371\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/settingsjsonfortests_searchpaths.png\" alt=\"add searchpaths settings to json file\" width=\"663\" height=\"202\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/settingsjsonfortests_searchpaths.png 630w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/settingsjsonfortests_searchpaths-300x91.png 300w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>Debugging Tests<\/h2>\n<p>In this latest release, we\u2019ve updated test debugging to use our new ptvsd 4 debugger, which is faster and more reliable than ptvsd 3. We\u2019ve added an option so that you can use the legacy debugger if you run into issues. To enable it, go to <strong>Tools &gt; Options &gt; Python &gt; Debugging &gt; Use Legacy Debugger<\/strong> and check the box to enable it.<\/p>\n<p>As in previous releases, if you wish to debug a test, set an initial breakpoint in your code, then right-click the test (or a selection) in Test Explorer and select <strong>Debug Selected Tests<\/strong>. Visual Studio starts the Python debugger as it would for application code.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-7365\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/debugtests_VS2019-2.png\" alt=\"debug python tests in VS2019 16.3 P2\" width=\"747\" height=\"1014\" srcset=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/debugtests_VS2019-2.png 747w, https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/debugtests_VS2019-2-221x300.png 221w\" sizes=\"(max-width: 747px) 100vw, 747px\" \/><\/p>\n<p><em>Note: everyone that tries to debug a test will find that the debugging does not automatically end when the debugging session completes. This is a <\/em><a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fptvsd%2Fissues%2F1571&amp;data=02%7C01%7CTyreke.White%40microsoft.com%7C73b84b20578b418f92fd08d71a5239bd%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637006812815745308&amp;sdata=si0X%2FQ0%2FH83vt3vTaQoqSmHaU%2BcmuhDqDJXUna1MTpI%3D&amp;reserved=0\"><em>known issue<\/em><\/a><em> and the current workaround is to click \u2018Stop Debugging\u2019 (Shift + F5).<\/em><\/p>\n<p>There\u2019s also the \u2018Test Detail Summary\u2019 view that allows you to see the Stack Trace of a failed test which makes troubleshooting failed tests even easier. To access this view, simply click on the test within the Test Explorer that you wish to inspect and the \u2018Test Detail Summary\u2019 window will appear.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-7359\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2019\/08\/testdetailsummary_window.png\" alt=\"Test Detail Summary View for VS2019 Preview 2\" width=\"1234\" height=\"537\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>Try it Out!<\/h2>\n<p>Be sure to download Visual Studio 2019 (16.3 Preview 2), install the Python Workload, and give feedback or view a list of existing issues on our <a href=\"https:\/\/github.com\/Microsoft\/PTVS\/issues\">GitHub repo<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we are releasing Visual Studio 2019\u00a0(16.3 Preview 2), which contains newly-added pytest support a re-worked unittest experience for Python users. Our latest updates apply to both Python Projects and Open Folder workspaces. In this post, we&#8217;ll take a closer look at this new experience.<\/p>\n","protected":false},"author":6541,"featured_media":7361,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,5],"tags":[647,17,648,649],"class_list":["post-7348","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-visual-studio","tag-pytest","tag-python","tag-unittest","tag-visualstudio"],"acf":[],"blog_post_summary":"<p>Today, we are releasing Visual Studio 2019\u00a0(16.3 Preview 2), which contains newly-added pytest support a re-worked unittest experience for Python users. Our latest updates apply to both Python Projects and Open Folder workspaces. In this post, we&#8217;ll take a closer look at this new experience.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts\/7348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/users\/6541"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/comments?post=7348"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts\/7348\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/media\/7361"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/media?parent=7348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/categories?post=7348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/tags?post=7348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}