I'm using Eclipse IDE for a project which uses pytest to write test cases. I have configured the pyunit environment to use "py.test runner" instead of "PyDev test runner", however, I'm not able to pass any arguments for pytest.
So this is the sample command I run in terminal -
pytest --server-version=5.0.0-3516 --sync-gateway-version=1.5.0-557 --sync-gateway-config-file resources/sync_gateway_configs/sync_gateway_default_cc.json --mode=cc testsuites/syncgateway/functional/tests/
Thanks for the help
So I figure out the way to pass the argument and select the test case one wants to run. So here is the snapshot of how to pass the argument.
To run a specific case use ctl + f9 and then select the case of that file. Now to debug it select the case using shift key.
Hope this helps others
Related
I'm using GNU Emacs 24.5.1 to work on Python code. I often want to run just a single unit test. I can do this, for example, by running:
test=spi.test_views.IndexViewTest.generate_select2_data_with_embedded_spaces make test
with M-X compile. My life would be simpler if I could give some command like "Run the test where point is", and have emacs figure out the full name of the test for me. Is possible?
Update: with the folowing buffer, I'd like some command which runs M-X compile with:
test=spi.test_views.IndexViewTest.test_unknown_button make test
where spi is the name of the directory test_views.py is in. Well, technically, I need to construct the python path to my test function, but in practice, it'll be <directory.file.class.function>.
This seems like the kind of thing somebody would have already invented, but I don't see anything in the python mode docs.
I believe you use the "default" python mode, while the so-called elpy mode (that I strongly recommend giving a try when doing Python developments within Emacs) seems to provide what you are looking for:
C-c C-t (elpy-test)
Start a test run. This uses the currently configured test runner to discover
and run tests. If point is inside a test case, the test runner will run exactly
that test case. Otherwise, or if a prefix argument is given, it will run all tests.
Extra details
The elpy-test function internally relies on the function (elpy-test-at-point), which appears to be very close to the feature you mentioned in the question.
See e.g. the code/help excerpt in the following screenshot:
In the test suite of a module, some test_foo.py files have helper functions containing doctests patterns in their docstrings. This causes PyCharm to offer Debug 'Doctests in test_foo' when selecting a function inside that file and trying via context-menu to debug just that function. It doesn't matter whether that function is before any actual test_...() function or at the end of the file, the mere presence of a single docstring with a doctests pattern causes PyCharm to exhibit this behavior.
If I just change all the >>> ... into />>> ... for example (to cripple the doctests search), then the behavior is as expected for a test file: context-menu on a function offers Debug 'pytest for test_foo.test_function'.
Is there a way to tell PyCharm to prioritize pytest over doctests if both are feasible?
Try Run -> Run ... menu option. The popup should have multiple choices including pytest
Please vote for the corresponding ticket in PyCharm's issue tracker https://youtrack.jetbrains.com/issue/PY-35985
I am trying to use PyCharm for unit testing (with unittest), and am able to make it work: the test runner nicely shows the list of test cases and nested test functions.
However, once the tests have been discovered, I cannot find any way to (re)run a specific test function: the only button available will run the whole list of tests, and right clicking on a single test function doesn't show any meaningful action for this purpose.
As you can imagine, it can take a long time unnecessarily when the purpose is to debug a single test.
How to achieve this? It is possible in Visual Studio for example, and seems like a basic feature so I assume I must be missing something.
Check the default test framework of the project...
You're perhaps used to 'unittest' being the default. Its enables me to put the cursor on the test definition and hit "SHIFT-CTRL-R" to run that one test.
The default seems to have changed to 'py.test' which has different behaviour and keyboard shortcuts. I'm on OSX so ymmv.
On Linux:
File -> Settings -> Tools -> Python Integrated Tools -> Testing / "Default Test Runner"
On OSX:
Preferences -> Tools -> Python Integrated Tools -> "Default test runner:"
With recent versions of PyCharm the availability of the 'right click' option seems intermittent.
One replacement is to go to Edit Configurations... and type the name of the class and method yourself. That's worked well for me, even if not quite as convenient
Under pycharm 2017.2.3:
the key step:
change the default test runner(unittests) to (nosetests or py.test), both ok.
then the IDE can run single test function now.
follow the steps of the below screenshots.
1. change settings:
2. run single test function:
3. run all test functions:
In Pycharm 2018.1: restart, delete the existing run configrations - suddently right-click provides an option to run a single test. :-/
Have you tried right clicking the test in the actual class? It should be possible to run the single test from there. I'd suggest a re-install if this is not available.
Please check whether you have the same test name repeated in two or more locations in the test fixture. I had the same problem and resolving the naming conflicts enabled me to right click on the test name and run it individually.
I had this problem with PyCharm 2018.3.
It seemed to be because I had a breakpoint in a strange place (at function declaration, instead of inside the function).
Clearing all the breakpoints seemed to restore the ability to debug individual tests
I am using TeamCity to test my code. I am using command line from TC and I am running a python test suite that tests the code.
I defined an environment variable (named "Server") and gave it a value ("production") and I want to pass it in a way that my python script will be able to access it and save it's value in the code.
I tried looking in TC documentation as well in Python's documentation and I couldn't find it.
I will appreciate your help.
Probably you should use os.environ
assert os.environ['Server'] == 'production'
While writing an application parsing command line arguments I would like to run it with various parameters.
I don't want to create a Run Configuration for every possible command line argument that I want my script to test with. Is there a way in PyCharm (and I guess with any JetBrains IDE) to make a Run Configuration that asks for the Script parameters when executed?
I am currently using PyCharm 3.1 (EAP).
Currently the only possibility is to use the "Before launch | Show this page" option.
I've found today that now is possible to ask for parameters using the "Prompt" macro on the "Run configuration" parameters field.
https://www.jetbrains.com/help/pycharm/code-running-assistance-tutorial.html#parameter-with-macros
Although yole's answer is the de facto way to be prompted for thw arguments before running a program, it is slightly annoying because:
the dialog is visually overwhelming and cluttered instead of focused on what you want to do;
you have to tab to reach the arguments field if you want to use the keyboard exclusively (and why not?);
Nothing you could do about that. (Except maybe file a ticket. Have you done that?)
I'm just adding what I used to do before I knew about Googled for this option for the sake of completeness (obvously, this is a hack in the least glamorous sense of the term). But it did suit my workflow as I often only had discrete lines to test with, and didn't switch that often.
Create a new configuration set to the same file, but with a special 'magic' parameter;
Add code to your script to check if the magic is there;
Use a string variable instead of sys.argv (pass it through lambda args: [__name__] + args.split() to reduce the boilerplate);
???
Profit;
I'm doing this on a Mac, but hopefully this will be helpful for Windows or Linux.
Go to Run > Edit Configurations
There will be a dialog box that opens.
Script: file you want to run (ending with .py)
Script Parameters: the command line arguments
Working Directory: directory where your project is.
My simple answer is adding another wrapper as the cover in the source code which will run on the selection you made through code branch or external command or file, so choosing different branch is just a 'ddp' tap distance in vim(line change for parameter settings). You dont have to depend on pycharm updating by building your own code world:)