I am using Behave to write BDD tests. The problem I have is that I am unable to create debug environment for these tests. I have successfully created an external tool run environment but that is of little help when I want to use breakpoints and debug the code.
Anyone who uses Lettuce/Behave/Freshen/Cucumber and could let me know how is the debug environment setup?
Found a solution on the Eclipse help page : http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-exttools-running.htm
It is possible to debug python steps (*.py) files in Eclipse IDE.
Belove solution works for:
Windows 7
Behave framework from https://pythonhosted.org
Just make:
Copy behave-script.py to directory that are located .feature files. You can find this file in Python27\Scripts\
In Eclipse add new "Debug as...->Debug Configuration->Python Run"
In a project choose your project
In Main module choose behave-script.py
Hit run and set brakepoints
Although you didn't mention Morelia (another BDD tool for Python) I thing you could try it. It doesn't need any special setup to integrate if traditional unittests works for you. Morelia's documentation: https://morelia.readthedocs.org/en/latest/
Related
I'm setting up a Django project for the first time using Pycharm, and I'm trying to figure out what the configurations do.
I have looked online at the documentation, but it seems to be more focused towards people who already know what configurations do.
I'm assuming it is used to set up my localhost, however I'm unsure. Any help would be greatly appreciated!
In an informal way, we can define PyCharm configurations as a comfortable way to start a new process.
Suppose that you have a Python script called main.py. If you have to run it via command line you will type
python main.py
In the same way, PyCharm offers the possibility to run this script using configuration. It's sufficient create a new Python configuration and setup the script path (location of main.py) and the relative python interpreter.
In fact, can happen that some scripts must be run using a virtualenv or a specific enviroments. For this reason, at the creation of PyCharm configuration we need to specify also python interpreter.
Configurations are not used just to start python scripts, but it's possible to create different types.
As you pointed out in your question, it's possible to create configurations also for Django.
A typical usage in this case is to create a configuration to start the runserver.
But this is not all, because it's possible create configurations also for django commands, for migrations and also for Unit Test.
Pycharm configurations are useful because in this way, no need to setup every time all environment to start a process, but you need just to create configuration and save it. You can use it whenever you want.
Last but not least, using configurations allow you to debug your code easily.
Configurations can be started also in debug mode.
PyCharm documentation
When you run your code/project in PyCharm, maybe you need to specify some set of environment variables, the entrypoint is a particular script in your project, maybe there's some other script you always need to run first before you can run your project, or lots of other fiddly things that are a pain to type in every time.
The purpose of PyCharm "Run Configurations" is to let you save all these kind of things into a single method of running your project with a single click or shortcut.
Django Configurations are a type of Run Configurations with a few extra Django-specific config options thrown in. The default settings in the Run Configuration are sensible (running on localhost:8000), although you will need to make sure you specify the location of your Django Settings File.
How I config Run/Debug Configurations in Pycharm Community:
Add a Python Configuration
Script path: "path to manage.py"
Parameters: runserver "host":"port" "option like '--noreload', '--nothreading'"
Python interpreter: "path to venv"
Now you are able to run with Shift + F10
In order to pycharm general setting left-top File>Setting
screenshot..
enter image description here
Python Setting....
Open a project or import
After open or import you view project name option in rigth-top bar like this
enter image description here
on click you can view configuration option. click it and view this form for all python or other environment setting.
enter image description here
I found the configuration for cpp (https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/Debugger/gdb/Windows%20Subsystem%20for%20Linux.md) and tried to change it for python debugging but it doesn't work. Any suggestion to make it work?
It should be mentioned that the Python extension for VS Code does not officially support WSL yet, but the enhancement request has been made and we do plan on supporting it.
Beyond extensions installations, IDE_PROJECT_ROOTS environment variable also may affect the debugger. For usual WSL standalone python code debugging, making sure this variable is not set (or set to the location of the files) when the VS code is opened helps.
For "step into" debugging of jupyter notebook having the python files path(s) as a part of IDE_PROJECT_ROOTS (for example export IDE_PROJECT_ROOTS="/tmp:/foo_pythonfilespath" set in .bashrc) will help to carry out "step into" python-code debugging in VSCode.
This is now supported and just requires installing the Microsoft Python extension and then to quote the documentation on remote debugging with WSL:
Once you've opened a folder in WSL, you can use VS Code's debugger in
the same way you would when running the application locally. For
example, if you select a launch configuration in launch.json and start
debugging (F5), the application will start on remote host and attach
the debugger to it.
See the debugging documentation for details on configuring VS Code's
debugging features in .vscode/launch.json
I run Python program which uses couple of source paths on runtime.
I put these rows on my /.bashrc file:
source home/raphael/kaldi/aspire/s5/cmd.sh
source home/raphael/kaldi/aspire/s5/path.sh
So when I'm running from terminal everything works fine and Python manage to locate paths.
However when I'm trying to run through PyCharm for DEBUG purposes mostly it seems that PyCharm can't locate the paths.
Is there anyway to add the paths manually for PyCharm or make it read /.bashrc file. What I am missing?
You can try using the options available in the Run/Debug Configuration settings (Run > Edit Configurations...)
You can set environment variables individually (such as $PATH), or at the bottom is a section to define external tools (scripts) to be run when your Python code is run or debugged. From that sub-section, you could set your bash scripts to be run each time you start debugging.
Alternatively, see if using os.environ would work for your project. Check the docs for more information.
I'm currently looking for a nifty Python/Django IDE and came across PyCharm from JetBrains which I tested for about a week now and I'm quite impressed by this piece of software.
However, I've read that IntelliJ Ultimate with JetBrains own Python Plugin offers about the same Features as PyCharm itself, so I went ahead and gave it a try, but experienced some issues which I didn't have within PyCharms.
In IntelliJ, the built in Feature 'Tools > "Run manage.py Task..."' works with most (e.g. runserver, startapp, syncdb, ...), but not with all commands:
Almost all sql-related commands like "sql", "sqlall", "sqlclear", ... are shown as available commands, but raise a "No Applications" error message when entered.
In PyCharm those commands works fine.
Running the test suite via "test" opens a box where I have to choose the applications which I want to test. However, there is only one entry "[All Applications]" and running it causes several Exceptions to be thrown.
Adding some new Applications to the "settings.py" file has no effect on "Run manage.py Task..." whereas in PyCharm it adds new commands to it. I've tried this for example with "django.contrib.gis" to enable "ogrinspect"
All those issues lead to the assumption that IntelliJ somehow fails to recognize the installed django applications. Did I miss some configurations or settings in IntelliJ which are already set in PyCharm?
To further explain what I did exactly:
In IntelliJ I created a new project "Python Module" then enabled Django as desired technology.
In PyCharm I just created a new project of type "Django Project".
All following steps were exactly the same.
Okay, so apparently the culprit is the IntelliJ IDEA Project Creation Wizard.
If you create a new project within PyCharms and choose Django Project as desired Project type, it just works. You don't have to configure anything else.
To do this in IntelliJ IDEA, create a new Project, choose "Python Module" as type and check Django as technology. In the new project go to "File > Project Structure", navigate to "Facets", choose your Django Module on the right and set the "Settings:" option to point to the specific "settings.py" file.
After this configuration, everything should work as smooth as in PyCharms.
I consider this problem as a bug, as the Wizard creates the basic project, including a "settings.py" file, but doesn't add it in the project settings. Plus, you don't get any warning that such a strongly needed settings file is missing.
In search of a Python debugger I stumbled upon Aptana, which is based on eclipse.
Often, I want to debug a single python script. However, Aptana won't let me run/debug the currently opened file directly.
Instead, it requires me to create a debug/run configuration for each file I would like to run/debug. Alternatively I could create a Python project in Aptana.
But: I don't want to. I just want to be able to run or debug the currently opened file. This way I would like to debug my scripts without being forced to create a project first (for each single script!).
Can it be that hard?
This is because Aptana/Eclipse doesn't "realize" that the file you opened should be debugged using the Python debugger as it's not associated with a Python project/perspective (there's a lot of environment setup when a project is created in Aptana/Eclipse).
The simplest solution, IMO, would be to create a simple sandbox Python project and just stick your files in there to run/debug. Aptana should then realize you're dealing with Python and start running the Python debugger without setup (that's my experience w/ PyDev in Eclipse, at any rate).
See: Run External Python Programs with Eclipse PyDev (note: you really need a project, but your file doesn't need to be in it).