❔ Program can't find folder
My program works fine but when I instead run the main program's functionality from a test-project then it can't find the folder named "python_scripts"
I even put a duplicate folder without links in both project, original files with no links
Project 1 works fine called "PredictionService"
Project 2 doesn't work called "ComputationServiceTests" (even though it should be a copy of the essentials!)
18 Replies
I've tried looking at the path and "item include" configuration already
is
python_scripts
configured to be copied to output?Unknown User•14mo ago
Message Not Public
Sign In & Join Server To View
Yes sorry I closed it prematurely
I tried experimenting around with having both your suggestion and the previous CopyToOutput
I tried having only your solution, tested both "Include" and "None", both "Always" and "PreserveNewest"
I'm sure the globbing is correct since the projects works, it only doesn't work when launched from MSTest specifically for unit-testing PredictionService
The "None Update" is what existed before
The "Content Include" is what I added per your suggestion
I tried with erasing the "None Update" as well
Yes it is, you can see in the .csproj as well, it only doesn't work in the unit-test
Hopefully you can see that i tried <None + globbing + copyToOutput
have a look at what the active directory is when the test app is running
Yes I tried that and the active directory becomes the testFolder/bin/debug/python_scripts/
That folder and it's included scripts have been copied to exist there and everywhere plausible just to be sure
The .csproj also contains Include-statements for that path
and the value of
modulePath
?testFolder\bin\debug\python_scripts
I wrote both paths to console to be sure
And there exists the folder there
wait
so...
you're surprised that
testFolder\bin\debug\python_scripts\testFolder\bin\debug\python_scripts
doesn't exist?var x = Path.GetFullPath(modulePath); equals
"C:\Users\myself\LocalScripts\Pin AI\PostopPredictions\PredictionServiceTests\bin\Debug\python_scripts.python_pipeline"
var x = Directory.GetCurrentDirectory(); equals
"C:\Users\myself\LocalScripts\Pin AI\PostopPredictions\PredictionServiceTests\bin\Debug"
So the only thing that seperates them is the ending "python_scripts.python_pipeline""
Why it is a "." between the folder name and the file name as well as why "python_pipeline" does not have an ending ".py" I can't say. But that code works when run from the project.
I didn't write that, the government did, I blame my confusion on them
Haha 🙂
No but I'm stumped, I can't seem to solve this :/
Set a breakpoint at the line before the exception throws
inspect the value of
modulePath
in the debugger
add a Watch expression for Directory.GetCurrentDirectory()
and inspect its value
observe the fact that either
A) modulePath
is an absolute path, referring to a location that doesn't exist
or
B) modulePath
is a relative path that refers to a location that doesn't exist inside Directory.GetActiveDirectory()
fix itIf the path starts with "C:" it is an absolute path to my knowledge
I know that there is a folder "pythons_scripts" and a file inside named "python_pipeline.py"
The error relates to the module
"Python.Runtime.PythonException: 'No module named 'python_scripts''"
Have you... actually read that error? Or the value of
modulePath
?
I know that there is a folder "pythons_scripts" and a file inside named "python_pipeline.py"
"python_scripts.python_pipeline"
does not refer to a file named python_pipeline.py
inside a folder called python_scripts
, it refers to a file named python_scripts.python_pipeline
.Yes I did, I even mentioned my curiosity as to why it seems to be looking for a file called literally "python_scripts.python_pipeline" yet it still seems to find it
My question is why this is the correct syntax and the program works perfectly fine, but not when it's run from a unit-test
And yes I can see that the value of the string modulePath is just a sort of combined name of a folder and file as if it was imported through python
And please don't be snarky with me, I'm being polite, I'm a professional developer so I have a clue about basics
That's not snark, that's a question. I don't assume anything about anyone's level of knowledge here, it's counter-productive.
My question is why this is the correct syntax and the program works perfectly fine, but not when it's run from a unit-testeither A) the program doesn't work perfectly fine or B) that's not the program that's being run from the unit-test, or more granularly, the program isn't being run the same Bottom line, stop working around the problem, and work the problem. You're passing a bogus path to
Py.Import()
, causing an exception. You need to work backward from there to see where that bogus path is coming from. You'll probably find that some parameter or environmental value is getting setup differently in your unit test, or that the code running in your unit test isn't even the same code that's running in your main app.Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.