PyCharm: How to run behave.exe? - python

I want to use behave lib in my program. I write code as in behave-tutorial.
But, when I "Run" my tutorial-project, I see in PyCharm-console:
C:\Python27\virtualenv\Scripts\python.exe "C:/Program Files (x86)/JetBrains/PyCharmProjects/tutorial/steps/tutorial.py"
Process finished with exit code 0
I think what I must to use behave.exe for run my project:
C:\Python27\virtualenv\Scripts\behave.exe
How to get it?

You can configure your run as per your purpose please have a look to screenhots here:
taken from: http://automated-testing.info/t/bdd-framework-debug-testov-stepov/3392/3

Even though behave support is now in the Professional Edition, it's currently not in the Community Edition.
You can still call the behave module for a given feature directory.
Add a Python Run configuration, with no script and these options:
Interpreter options: -m behave
Working directory: path/to/feature/directory

I tinkered around with previous answers and got PyCharm CE 5.x working with Behave I have python 2.7 installed system-wide, and behave installed via PyCharm package management
Here is my run config:
Script: put dot (.) in here [this way PyCharm recognizes the configuration as valid and doesn't show red cross mark]
Working Directory points to the dirctory where .feature file is
Interpreter options: -m behave

For PyCharm Community 2016.3 on mac, setup a run configuration with:
Script: /usr/local/bin/behave
Script Parameters: path/to/feature/directory
Working Directory: path/to/project/directory
This way the run & DEBUG both work.

I have 2 features file (createX.feature and createY.feature) at feature directory but I want to select only 1
My configuration is
Script: createY.feature
Script parameters: --tags=#int --tags=#e2e
Interpreter options: -m behave
Working directory: $features_directory
The "Run" window shows this execution command
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -m behave createY.feature --tags=#int --tags=#e2e
but pycharm chooses the other feature file :(
But if I run the command at a terminal window, the command works!!
Edit: I have changed the feature file I want to execute for a better understanding: I try to execute the last one following alphabetical order
Edit 2: Solved It seems that behave does not like to have "scratch" files for control tasks at steps directory ... Once I deleted them, that handsome configuration works!!

Related

I want to use python option -m when i use pycharm debugger

Hi I got the project on the github, I want to analyze this code using debugging.
The project uses python 3.6 and requires next command when running
python -m pixloc.run_Aachen
pixloc is package (directory) name and run_Aachen is python file name.
When I run this command using Pycharm, It is successful
but When I run this using Pycharm Debug mode, It is fail
the following image is my Run/Debug Configuration
enter image description here
What can I do for this problem
I try to use setuptools.setup(), but this isn't work
I just want to use -m option in debug
Your run configuration is currently set to to run a Python script (i.e., as python ./path/to/script.py), but you want to execute a module (i.e., python -m package.subpack.mod).
To change your run configuration to one that executes a module, do the following:
Under the run configuration, click on the first dropdown that reads "Script path" and change it to "Module name".
Then, specify pixloc.run_Aachen in accompanying testbox.

Opening Python script mode on a MacBook

I have a MacBook air and have tried opening Python in terminal but when I open it, it opens Python interactive mode. Does anyone know how to open Python script mode please.
I’ve tried typing in things such as Python or Python 3 like safari suggests but that didn’t work.
There is no 'script mode'. You can create a Python script using TextEdit or another editor, save it as myfile.py, and then run it with python myfile.py.
for running what you are calling 'script version' of python you should choose a python file to run and make sure is written in the same or in a compatible version to the python you are running it with (python2, python3)
For running an example script:
python main.py
You need to be in the directory containing the file so make sure you are there before running the command. Using python runs the first version of python you installed, so if you want to use an other you should use:
python2 main.py
python3 main.py
etc
Assuming you've stored your script in a file named itworks.py, the simplest thing is to type the command python3 itworks.py in a terminal window after you've moved to the directory containing the script. Alternatively, you can type python3 followed by a space, then locate your python script in the Finder and drag and drop it into the terminal. This will expand to the full path to the file, allowing you to run a script located elsewhere than your current directory. Don't forget to press return...
In older versions of MacOS you could say python, but that uses python 2 which is no longer supported so you should go with python3 for any new development. (With MacOS Ventura, python 2 seems to have been removed.)
If you have multiple versions of python, you can use the command which -a python3 (or python) to see all versions on your PATH, and the order in which they will be found. PATH works on a first-come-first-served basis, but you can override by using the fully qualified path name to an alternative python.
Yet another solution, for when you want a more permanent script you will use many times in the future, is to use a "shebang" line as the first line of your script. For example, I wrote the following tiny demo:
#!/usr/bin/env python3
print('It works!')
The first line says to parse this script with the first python3 interpreter found in your current environment's PATH. You could replace that with an explicit path such as #!/opt/homebrew/bin/python3. Now make the script executable: chmod a+x itworks.py. You can now run the script from the current directory by typing ./itworks.py. (The leading ./ tells your shell you know it's in the current directory, and is intended as protection against trojan horse scripts.) If you want to be able to use the now-executable script from anywhere, add it to a directory on your path such as /usr/local/bin, and you'll be able to run it by just typing itworks.py.

Python 101 : Komodo edit - code not running in command

I have just opened up Komodo edit and can't run any code.
I just get this message in the command output:
/usr/bin/python: can't open file 'Python3-1.py': [Errno 2] No such file or directory
What do I do? I installed python3 again. Do I need to install it in the right place?
I think it say for you - I can't find your file.
You should try to check path to you file.
Then you should try to run your code from terminal. Open terminal app (gnome-terminal, konsole, xfce-terminal or etc. what you always using for this) and try run directly you file in you folder like this:
python Python3-1.py or python3 Python3-1.py or python3 -m Python3-1.py.
If all works fine - check you Komodo settings.Edit -> Preferences in Language block check in Python Default Python Interpreter
If not help you -please update you question for more information.
P.S. and you should try VS Code for python development. It have awesome integrated terminal and you can learing run all programs on command line, like you will do it in real life. Komodo Edit good editor, but not the best for this.

Launch configuration first_behave.feature references non-existing project python_behave_template-master error

I configured Pydev in eclipse and also installed behave and cucumber to run a sample project in BDD approach.
Each time i right click on the feature file (dirst_behave.feature) and Run as "Cucumber feature", i get the error -
"Launch configuration first_behave.feature references non-existing project python_behave_template-master."
I tried remapping the Python interpreter, but no luck. Any help in getting this issue resolved would be greatly appreciated.
I was using Pycharm IDE to run python scripts, but Behave approach doesn't work in Pycharm community version.(Screenshots attached for reference)
enter image description here
Each time i right click on the feature file (dirst_behave.feature) and Run as "Cucumber feature", i get the error -
"Launch configuration first_behave.feature references non-existing project python_behave_template-master."
I was using Pycharm IDE to run python scripts, but Behave approach doesn't work in Pycharm community version.(Screenshots attached for reference)
You can't run the *.feature script directly from Pycharm IDE.
Try to run your script from terminal:
behave feature/first_behave.feature
Behave works in Eclipse as well as in PyCharm (CE). But there is more handy work involved. Both IDEs allow you to run a generic command. Therefore, it should be possible to run it. This is especially needed when you need a debugger to diagnose the behave test run (but you normally need to provide your own script that imports the behave main() function same as the behave-script does).

Python curses Redirection is not supported

I am trying to use Curses in PyDev in Eclipse in Win7.
I have installed Python 3.2 (64bit) and curses-2.2.win-amd64-py3.2. When I input the following testing codes into PyDev:
import curses
myscreen = curses.initscr()
myscreen.border(0)
myscreen.addstr(12, 25, "Python curses in action!")
myscreen.refresh()
myscreen.getch()
curses.endwin()
It did not show any syntax error, so I think the curses was installed correctly.
However, when I ran it as Python Run, the output showed: Redirection is not supported. I do not know where this problem comes from. I googled a lot but can't find related information.
Recent PyCharm versions (I am currently running 2017.2, not sure when this option was added, or if it has been there the entire time) have the option "Emulate terminal in output console". Curses works with this option checked.
You cannot expect to use curses with a non-terminal.
Probably you get this because you are running the script from inside an IDE, like PyCharm or any other.
All IDEs do provide consoles that are not terminals, so that's where the problem comes from.
For a Pycharm user the solution given by codeape works fine :
Snapshot
You can't use any IDE to run python files with the curses package. I used to run in pycharm and naturally couldn't run.
Change to the command line to run:
for testing follow my following steps
on desktop open notepad and copy paste the code and save it as filename.py
open command line change directory to desktop use below command cd Desktop and hit enter type python example.py and hit enter, your program will definitely run
My workaround is to create a Run Configuration that calls a curses script. The little overhead is worth not having to switch to the terminal and manually run the script hundreds of times a session. I use Intellij but I imagine the process should be similar in PyCharm.
The desired result is the convenience of a button to run the script:
First create a script that calls the entry script, for instance:
ptyhon name-of-script.py
Then, to create a configuration for each script:
Go to Edit configuration.
Click the plus button and add a Shell Script.
Enter the path to a shell script.
Here is a picture of a directory with a couple of sample scripts.
I use this process to view my progress. My curses scripts are very modest so fortunately I can live without a debugger.

Categories