Allure ModuleNotFoundError but only on certain functions of the package - python

I am starting to work with Allure to make reports for my test automation team. My goal is to attach screenshots but I run into an error. The lines of code that prompt this error are:
import allure #This line runs fine
from allure.constants import AttachmentType #This one throws the error
Which throws: ModuleNotFoundError: No module named 'allure.constants'; 'allure' is not a package
I am using allure throughout different parts of the code without running into errors, for example I use the decorator:
#allure.step("Description of a step")
So the module is being correctly loaded. Upon further inspection on the internet I found links stating that I should uninstall previous packages such as pytest-allure-adaptor as seen in this other SO question. I did so but the error remains unchanged.
In order to give more context, I am using the following softaware:
IDE: Visual Studio Code
OS: Windows 7
Python version: 3.6
allure-pytest: 2.8.12
allure-python-commons: 2.8.12

It seems that in the version of allure that I was using allure.constants does not exist.
I solved my problem my changing that line to:
from allure import attachment_type
And then, to take the screenshot and adding it to the report:
allure.attach('screenshot', driver.get_screenshot_as_png(), type=attachment_type.PNG)
I hope this helps someone else in the future.

Related

Issue with new isort extension installed as from VS-Code Update October 2022 (version 1.73)

I'm using VS-Code version 1.73.1, with MS Python extension v2022.18.2, on Windows 10 Pro, Build 10.0.19045. After installing the October 2022 update of VS Code, when writing Python code I noticed nagging error diagnostics being issued by the isort extension about the import order of modules. Previously, I had never encountered such diagnostics.
I traced this behaviour back to the VS Code release notes for the Update October 2022. These announce the migration of VS Code to a new stand-alone isort extension, instead of the isort support built into the Python extension, by automatically installing it alongside the Python extension. When opening a file in which the imports do not follow isort standards, the extension is intended to issue an error diagnostic and display a Code Action to fix the import order.
Whilst the extension seems to work as intended, I found the issues described below:
1. Even after having executed the Code Action to fix the import order, a 'light-bulb' with the same error diagnostic and Code Action again pops up on moving the cursor to a new line of code.
2. The error diagnostic and Code Action 'light-bulb' are also displayed when moving the cursor to any new line of code, even when all lines of code in the file have been commented out; that is, effectively, there are no longer any import statements in the code, and therefore also nothing to be sorted.
I'd appreciate comments on whether this is a recognised issue in VS Code, and if so, whether any workarounds are available. It defeats the purpose of having an 'error lightbulb' pop up on every line of code, just to find a code action recommending to fix the import order, even when this requires no fixing.
I have opened this question on this forum as recommended on the GitHub 'Contributing to VS Code' page.
Upgrade the isort extension version to latest(v2022.8.0).

Unable to import modules in pycharm in spite being installed in the used python interpreter

Even after installing dash - getting module import error.
Pycharm does not throw any compilation errors on the line as well.
How could this be resolved?
I tried everything as suggested in comments and stuff known to me but could not resolve this - have done this a thousand times earlier but don't know what went wrong this time.
The only solution the=at worked was to create a new project, copy files over manually and then create a fresh interpreter and VE.

Visual Studio Code adding lines between code in Python terminal causing syntax errors

I'm running Python code in VS Code (1.28.2, with the Python, and Python Extension Pack extensions) and am using the 'Run Selection/Line in Python Terminal' (Shift+Enter) functionality to just run selected code in the Python terminal.
This has always worked well, but today I'm getting a new line added between each line of code in the terminal, i.e. if I ran:
import heapq
import pickle
the output in the terminal would be:
>>>import heapq
>>>
>>>import pickle
At first, this just seems like an annoyance, but any for loops or functions now come out with an indentation error...so essentially I can't successfully run any code.
I've tried re-installing VS Code as well as installing an older version of VS Code but all give the same problem.
It's so odd because it was working fine and then all of a sudden it changed. The only thing I can think of that has possibly changed is I installed the JSON Tools extension, but I don't believe this would change anything within Python (and I've tried uninstalling this, and not loading it again when reinstalling VS Code from scratch)
Any help would be greatly appreciated!
It's a bug that will be fixed in the 2018.9.1 release of the Python extension.

Strange Python package import behavior in Visual Studio

I encountered a very strange behavior of Python project in VS 2017.
Suppose, I have a "library" Python project and also a unit testing project.
When I add the following lines
import unittest
import Metric.metric as metr // module from the first project
into file in the second project it works fine (I even can press F12 on 'unitests' and go to __init_ file of unittest framework, or on 'metr' and see contents of metric.py file) but only until VS reload.
After reloading the second line no longer works!!! The first line may work but just for a while. After some time (and may be another VS reload) it also breaks down - neither F12 nor unit test discovery not working
Moreover, after I type 'import' and press Ctrl+Space, a 'unittest' hint string also no longer available in IntelliSence popup!
What may be the reason of such a strange problem?
I also tried to reproduce it on another toy example with no success - everything works as expected! So you may also be not able to reproduce the problem. The only hope is for someone's intuition.
My settings (all up-to-date):
Visual Studio 2017 15.5.2
Environment - Python 3.6 (64 bit) (global default)
Comments in python are with # instead of //

Python 3.3.5 time module missing

When I try to import time I get : No module named time
I have tried other time modules(datetime and timeit) and they work fine. I decided to check my installation and I can't find time.py anywhere. I checked the Lib, Scripts, libs and include folders, but can't find it anywhere.
Anyone know what I can do to fix this? Maybe download the .py and put it in Lib myself?
I am using Python 3.3.5 with PyCharm IDE. Only extra scripts I've installed is EasyInstall and PRAW.
The import does work. When PyCharm said No module named time, I assumed I would get a compiler error and started trying to fix it.
However when I eventually just ran the code it worked fine. I expect PyCharm doesn't detect the time module as it's a dll and not a py as noted by Martijn in the comments. This is on PyCharm Community Edition 4.0.4.
I tried playing with virtualenv and a host of other things, but I eventually went to Preferences -> Build, Execution, Deployment -> Console -> Python Console, and in the "starting script" box, I added two lines:
sys.builtin_module_names.append('sys')
sys.builtin_module_names.append('time')
This got rid of errors I had with both sys and time. Once I did that, I even get autocomplete for both of those modules... weird.

Categories