Import error running pytest - Google Cloud Function - google-cloud-functions

My folder structure is like this
cloud_fn_dir
cf1_dir
main.py
util.py
requirements.txt
test_main_cf1.py
cf2_dir
main.py
requirements.txt
test_main_cf2.py
cf3_dir
main.py
requirements.txt
test_main_cf3.py
I am executing unit tests and generating coverage report using command - pytest -v --cov=main --cov-report=html
If I am executing the command from inside the Cloud function folders i.e. cf1_dir or cf2_dir folders then the pytest command works as expected and executes the unit tests and generates reports inside that folder.
But I wish to execute all the unit tests at once and generate a single report and hence I tried to execute the same command from outermost folder i.e. cloud_fn_dir and encountered Import Error where the test_main_cf3.py file is trying to import Class of cf1_dir main.py file.
Each of the test file is importing it's respective main.py file in it and creates an object and calls the methods to test. So when I execute the pytest command it is making the last test file i.e. test_main_cf3.py to import main of cf1_dir main.py and execute the methods. Pytest is trying to import the first encountered main.py class
How do I resolve this import error ?

Related

at top of python program, a command "import csv" "is not accessed" where to find it

import csv
fails, alert "csv.py" is not accessed
yes, there is no file of that name in my current working directory.
Where can I locate a copy of csv.py to use in my current project.
import urllib.request, urllib.error, urllib.parse #this command works
import obo #this command works because I have obo.py in my directory
import csv # csv is underlines with white dots, csv is not accessed
where do I seek csv.ph?
running windows Visual Studio version 1.73.1
Newbie error. The warning from Visual Studio only meant that I imported a module but didn't use it in the program.

Converting python script to exe. Failed to execute script

I have made a game using pygame and now want to convert the script to an exe file. However, when doing this and starting the exe file I get an error saying "Failed to execute script (main.py)". I have tried everything from youtube videos to reading similar questions on Stack Overflow. But nothing works, I get the same error every time. How can I solve this?
Does it have to do something with my imports?
The import that I use in my script:
pygame
random
winsound
mixer (from pygame)
Avoid all of these problems and use PyInstaller (link to related question):
Download this library with pip by typing in the Command Prompt:
py -m pip install pyinstaller
Then, type cd [path to the file].
Finally, type py -m PyInstaller --onefile [script name].py.
PyInstaller will turn your code into one .exe file, in the folder dist, analyzing the modules you need.
After the installation, you can then delete all the other files, like the folder build for example.
If you need other attached files, like images, put them in the folder where the .exe file has been created.
Anyways, if you type exit() anywhere in your code, PyInstaller will raise an error. Simply import sys and type sys.exit() instead.

ModuleNotFoundError when using local dependencies

The repo works on my machine but not on gcloud.
Structure of repo (on Google Cloud Source Repo):
project/
├── localdep.py
└── mylocalpackage/
└── main.py
In main.py:
import localdep
Yet I receive the following error:
ModuleNotFoundError: No module named 'localdep'
What am I doing wrong?! There is no problem running this on Pycharm on my machine, yet when I push to gcloud there is...
The proper structure should be to have the main.py at the top level and the other files on the nested folders. You can take a look into this, which talks about Structuring Your Project.
Just in addition, I have tried with both from ..localdep import * and from ..package import localdep, and other like from ... import localdep, but either I receive ImportError: attempted relative import with no known parent package, or ValueError: attempted relative import beyond top-level package.
It worth to rethink your project structure.

Can the Import command be invoked via the Design Automation API?

I'm trying to invoke the AutoCAD Import command via the Design Automation API. This works fine from accoreconsole.exe locally, and while the Design Automation API accepts the Import command without error, it proceeds to the next command without importing anything.
In the excerpt of a Design Automation API output log below I'm invoking the Import command both directly from the generated script file and via SendStringToExecute via my plug-in. In the latter case I've pulled the full local file path.
[10/19/2017 06:20:18] Command: Import
[10/19/2017 06:20:18] Enter import file name: "input.stp"
[10/19/2017 06:20:18] Command: ProcessChamberDrawingCloud
[10/19/2017 06:20:19] Command: (command "Import" "\"T:\\Aces\\Jobs\\f4ba423419294f7eacf0d9fac71e790f\\input.stp\"")
[10/19/2017 06:20:19] Import
[10/19/2017 06:20:19] Enter import file name: "T:\Aces\Jobs\f4ba423419294f7eacf0d9fac71e790f\input.stp"
[10/19/2017 06:20:19] Command: _.quit
The 'IMPORT' command in Forge Design Automation have some problem, it doesn't spawn "AcTranslator.exe" process. we are working on some other alternative, we will keep you posted.
IMPORT is a two step process in AutoCAD
First it will spawn a child process like this AcTranslator.exe -i
"input.stp" -o "output.dwg"
When translation is done, a notification is sent to user in the
AutoCAD UI [Right Most corner of AutoCAD Main Window] when you click
on the notificaton bar, translated entities from output.dwg are merged in to current
drawing.
Currently, we see problem at first step.
edited
We have fixed this problem:
I have answered in another stack over flow post Import-In-Forge
For STEP files, the IMPORT command depends upon the AcTranslators.exe and several atf*.dll files. Does your environment have those files, will be the 1st question? But I'm still checking if there is some other approach.

How to run several yiic commands in one .bat file?

I have an ImportCommand class which reads a file and imports the data from that file to a database. The command itself works fine.
However, I need to run the same command several times with different files.
My .bat file:
#echo off
cd c:\xampp\htdocs\mysite\protected\
yiic import c:\sourcefiles\users_1.csv
yiic import c:\sourcefiles\users_2.csv
yiic import c:\sourcefiles\users_3.csv
The first command runs then the script stops and files users_2.csv and users_3.csv are not processed.
After struggling with this for a while, I found this answer: How to run multiple .BAT files within a .BAT file
So the .bat file should be:
#echo off
cd c:\xampp\htdocs\mysite\protected\`
call yiic import c:\sourcefiles\users_1.csv
call yiic import c:\sourcefiles\users_2.csv
call yiic import c:\sourcefiles\users_3.csv
Use CALL command. Without CALL, control is transferred to other batch and is not returned.
Try this
#echo off
cd c:\xampp\htdocs\mysite\protected\
yiic import c:\sourcefiles\users_1.csv && yiic import c:\sourcefiles\users_2.csv && yiic import c:\sourcefiles\users_3.csv
This will execute the desired command one by one . It only proceeds one operation is successful.