"No Tests were found" in Pycharm Professional 2019.1 using Behave - python

Starting Python BDD, using Behave in pycharm 2019.1 pro. Just started learning Python and Pycharm IDE.
Used a basic example to run a feature file with one scenario in it.
When I run using Pycharm Terminal, the scenario runs fine. When I do the same while right clicking on the Scenario in the editor, I get the message at run time, "No tests were found".
I have searched on SO but responses are for unit tests not for BDD tests.
I went into the run/debug configuration and have tried setup working directory to my feature folder or the project folder, but still the same issue.
I previously had python 3.7 but now using python 3.6 (both installed) and the interpreter is set to behave

I got it working but uninstalling pycharm, python 3.6 and python 3.7 folders completely (includuing hidden folders from private # root) from my machine, fresh install pycharm with python 3.6 and then behave. Tests work now.
No idea exactly why it happened except that it could be some conflicting config due to different python versions.

Related

Python not found

I'm working on a project in a python virtual environment, the project was started on a pc with python 3.8 installed and consequently python 3.8 was used in the virtual environment, or I had the need to continue the project on another pc, so I loaded all on GitHub, in the end I downloaded it to another PC with python 3.11 installed, the files are all there but when I try, inside the virtual environment, to open python by writing python or python3 in the terminal, it shows up this error: Python not found; Run with no arguments to install from the Microsoft Store or disable the link from Settings > Manage apps Run aliases. I then tried to see if it only showed up inside the virtual environment, but the same thing happens outside as well.
I tried to do various things among those suggested in other forums but they didn't work, the problem persists, I'm a bit lost, it's the first time this has happened to me.
Sorry to bother, maybe it's the simplest problem there is to solve but I don't know where to start
Trhanks
The problem is the different version of python on the two computers... the content of the pyvenv.cfg file must simply be changed which, when creating the virtual environment, is based on the installed version. Here you just need to change the path to reach the python.exe file installed on your computer and then change its version by inserting the correct one.

IDLE and PyCharm are using different versions of python, despite the python.exe PyCharm is using being installed in the same directory

I cloned a python environment and recreated it on a new machine using Anaconda Navigator with a yml file. My script runs fine in the new environment using PyCharm. The python version of this environment is 3.9.0. However the script doesn't run with IDLE because IDLE is running version 3.11.0.
IDLE is located at:
C:\ProgramData\Anaconda3\envs\CloneETL3\Lib\idlelib\idle.pat
The python interpreter which PyCharm uses is located at
C:\ProgramData\Anaconda3\envs\CloneETL3\python.exe
How can IDLE have a different version from the python interpreter when they were just installed fresh? How can I prevent multiple versions of python from running on my machine? I made sure to create a new project in PyCharm, use an existing interpreter using conda and point it to the exe I described above.
The environment was first created from a clone of my ArcGIS Pro environment.
Thanks for the help!
This is quite common in most editors. I use vscode which is similar to pycharm and the user can select the version of python (or other languages) that they wish to run.
It look like this:
The reason for this is that some users have the requirement of being compatible with previous versions. You should be able to select the latest version of each.
Alternatively you can delete all versions leaving only the one version that you desire, this would avoid confusion...
You could refer to this answer for that option: How to completely remove Python from a Windows machine?

How do I activate a VSCode environment from ssh?

I am currently using VS Code on a server (through SSH). Everything works fine, and I installed Python packages and work with Python notebooks.
Now, I want to login to the server (not a problem) and run the Python code I created on VSCode, rather than executing it remotely.
My main issue is that I am not sure how to activate the Python environment (if there is one) that VSCode server's run so that the code can execute.
Is that possible?
I see I have a .vscode directory in my home directory, and there are package installation there.
After connecting vscode remotely, you can use it as a regular vscode, which is no different from running Python files locally:
install python
install pylance extension
choose correct interpreter
edit your code and run the python file.

VS Code Pytest Discovery Error Due to ModuleNotFoundError

I am trying to setup my VS Code debugger for pytest and am getting the error discovering pytests tests from the testing tab. The test I'm running works perfectly when run from the terminal but the VS debugger is not able to run it. In the testing tab, it directs me to the output where it shows a ModuleNotFoundError for logdna in the common.py file. That file has some other seemingly syntax errors but I believe VSCode is just not interpreting them correctly because the modules are in the code base. On the left you can see I ran pip3 install logdna to ensure logdna is actually installed.
Note that I am running inside a Poetry environment and have a .env in the project root directory.
Note also that I have reviewed and tried all answers provided here and none of the provided answers helped in my case: VSCode pytest test discovery fails
You are using virtualenv inside terminal. Here is clearly seeing in logs that python is installed inside /Users/.../pypoetry/virtualenvs/... folder.
But VSCode using default python (/usr/local/bin/python3) or at least non virtualenv version
You have to choose same interpreter in VSCode as terminal's one
What is virtualenv?

Why won't PyCharm see my libraries?

If I do something like "import selenium" (or any other kind of third party library) in a .py file and then run it from the terminal, it works just fine. But if I make a new file in PyCharm CE and do the same thing, it can't find the library / module.
How can I fix this or get it to point in the right location? I use a Macbook Pro.
You need to setup your project in PyCharm to use the Python interpreter that has your libraries:
Go to: file->settings->project->project interpreter
And select the appropriate interpreter from the dropdown. After selecting an interpreter, the window displays a list of libraries installed on that interpreter; this should further help you make the right selection.
I've faced a similar issue on Pop!_OS after installing PyCharm via Flatpak. I think the installation is somehow incomplete, as I've had these issues (among others):
Installer could not create the menu shortcut due to the lack of credentials. Unlike during a typical installation, it wouldn't ask for the password and instead I had to uncheck that option altogether.
Built-in terminal defaulted to sh. Even after changing to bash, it would not read my .bashrc and many commands were missing.
After changing the interpreter into a local virtualenv, it would just default to Python 3.7 (even though the version was actually 3.8) and it didn't see any of my installed libraries.
When I've tried to use a Docker Compose environment, IDE failed to detect Docker Compose installation.
I've eventually uninstalled PyCharm and downloaded it directly from Jetbrains website to make it work correctly.

Categories