Hello! has anyone else been having trouble running pytest on windows? I have everything installed but when I run a program with pytest included it says there is a permission error. I did some research and found out that this is most likely to do with the fact that windows doesn't want pytest to look through individual directories, but I just have no idea how to fix this.
If it helps, I am on visual studio code for my IDE. I have tried running the programs on both my laptop and PC, and neither have worked.
Here is a snippet of the error message:
E PermissionError: [WinError 5] Access is denied: 'C:\\Users\\lotur\\AppData\\Local\\Application Data'
if anyone has been having troubles with this or knows how to fix it, please let me know!
thanks,
Hello World, I hope everyone's having a fantastic day, and if not, hopefully tomorrow is better!
I have some questions about the assignment.
Firstly, should they always return correct? For instance, with the independent test I wrote a function testing something that I thought would return False but it returned True. My guess is that I should just leave that as a failed test instead of adapting my test to the function, should I make note of what happened that I didn't expect? Should I change the test? Should I just leave it as is?
Secondly, is more always better? If I can think of six unique situations to test for, should I? Or should I leave it at two good ones? Will this improve my mark?
Thirdly, should the tests I do choose to create be practical and simple? Such as, does the function give the right answer when given normal input? Or should I try and break it?
Lastly, how strictly should we follow your formatting guidelines? You've said that you prefer the name_test convention, and three spaced indents as opposed to tabs, should we follow these or are we free to deviate as long as it's consistent? I looked through the formatting guide but it didn't say whether using tabs for instance would lower our grade, just that spaces is preferred, just wanted to double check on that since nothing brings me joy quite like using tabs for indents.
I second this, I've got the exact same problem. I installed pytest just fine but am completely unable to run the test files I've created due to PermissionError. I'm also unable to use VSCode's test feature as well, likely because of directory permissions of some sort. Been troubleshooting for about an hour now and still no luck.
I swear, it's only Windows that pulls this kind of stuff. Been using Windows for 7 years now, and every time I've tried to code something semi-complicated, it's thrown some type of OS specific error; meanwhile on my Mac I almost never got any errors that aren't code-related.
EDIT: I found a work-around. Make sure you've got the entire folder/workspace open on your VSC and not just the particular file from that directory. I think it'll still throw perm-error's for other things but at least you can run the tests this way.
When I run my program, an error shows up on the IDLE Shell: "fileno = sys.stderr.fileno()" and "io.UnsupportedOperation: fileno". It also shows errors happening throughout parts of the pytest package. I've searched online for solutions but have come up short. Does anyone have a clue what this means?
I have been getting messages from several students regarding errors that crop up when using Pytest. It does seem that several IDEs and/or operating systems don't think Pytest should be allowed to do its job. There are a couple of things to try:
1. Try a different IDE, or try running Python from the command line.
2. Make sure you are running your IDE with administrator status.
3. Make sure the directory containing your Python programs is part of your project (or workspace, or domain, or whatever your IDE might call it)
4. Reinstall Pytest.
Final option: submit your assignment without having run the tests. Add a note in your internal documentation stating that you were not able to run your tests due to technical problems. You will not lose grades for this.
There is no penalty for having lots of tests! However, each test should test a situation that is unique in some significant way.
For example, testing the "list the primes" function individually on every integer from 1 up to 1000 (i.e. writing 1000 tests) is probably not sensible.
If a Pytest test gives an unexpected result, there are two possibilities:
1. There is an error in the unit (i.e. the function) being tested.
2. There is an error in the assertion.
Both of these situations are important. The assertion describes what the tester expects will happen ... maybe the tester misunderstands what the function is supposed to do. Exploring this can help the tester. If the assertion is correct, then the unit is incorrect and will need to be repaired before use (or released with a "known issues" report, which is what happens a lot in real life!). The tester may have thought of a situation that the author of the unit had not considered. This is exactly why we do testing of this kind.
So if you have created a test that gives a result that you did not expect and you are sure that your assertion is correct, you should absolutely include the test. You should add internal documentation explaining why the test should have passed.
It is not necessary to include a test with an assertion that is known to be false, just to get Pytest to print out its failure report. I did this in our demonstration code just so that we could all see what happens when a test fails.
One of the maxims of software design is "Never trust the user"
Ideally every function we write should be bullet-proof: calling it with incorrect parameters should be handled gracefully. In the real world this is hardly ever the case. Most well-documented functions will specify the number and type of parameters needed, and if the user deviates from those restrictions then the function is allowed to fail.
But it's perfectly valid to test a function on bad input just to confirm that it does fail as it should. This can be very useful information. I recall a situation where a piece of software was supposed to do one of several different things, based on a parameter value being between (let's say) 1 and 5. A user discovered that it was possible to get the software to accept a parameter value outside that range, and then do something unpredictable. In Python, parameters being untyped is a particular hazard. For example, suppose we are expecting a parameter to be a list, but the user provides a tuple instead. Our function would still be able to iterate through the provided input, but attempting to change it would fail.
Thanks for picking up the typo
The correct date is the one on Assignments and Due Dates
Winerror when running pytest
Hello! has anyone else been having trouble running pytest on windows? I have everything installed but when I run a program with pytest included it says there is a permission error. I did some research and found out that this is most likely to do with the fact that windows doesn't want pytest to look through individual directories, but I just have no idea how to fix this.
If it helps, I am on visual studio code for my IDE. I have tried running the programs on both my laptop and PC, and neither have worked.
Here is a snippet of the error message:
E PermissionError: [WinError 5] Access is denied: 'C:\\Users\\lotur\\AppData\\Local\\Application Data'
if anyone has been having troubles with this or knows how to fix it, please let me know!
thanks,
Louise Turner
Questions about the testing:
Hello World, I hope everyone's having a fantastic day, and if not, hopefully tomorrow is better!
I have some questions about the assignment.
Firstly, should they always return correct? For instance, with the independent test I wrote a function testing something that I thought would return False but it returned True. My guess is that I should just leave that as a failed test instead of adapting my test to the function, should I make note of what happened that I didn't expect? Should I change the test? Should I just leave it as is?
Secondly, is more always better? If I can think of six unique situations to test for, should I? Or should I leave it at two good ones? Will this improve my mark?
Thirdly, should the tests I do choose to create be practical and simple? Such as, does the function give the right answer when given normal input? Or should I try and break it?
Lastly, how strictly should we follow your formatting guidelines? You've said that you prefer the name_test convention, and three spaced indents as opposed to tabs, should we follow these or are we free to deviate as long as it's consistent? I looked through the formatting guide but it didn't say whether using tabs for instance would lower our grade, just that spaces is preferred, just wanted to double check on that since nothing brings me joy quite like using tabs for indents.
Cannot Submit Assignment 2
Hi is anyone else not able to submit the assignment on Onq?
RE: Winerror when running pytest
I second this, I've got the exact same problem. I installed pytest just fine but am completely unable to run the test files I've created due to PermissionError. I'm also unable to use VSCode's test feature as well, likely because of directory permissions of some sort. Been troubleshooting for about an hour now and still no luck.
I swear, it's only Windows that pulls this kind of stuff. Been using Windows for 7 years now, and every time I've tried to code something semi-complicated, it's thrown some type of OS specific error; meanwhile on my Mac I almost never got any errors that aren't code-related.
EDIT: I found a work-around. Make sure you've got the entire folder/workspace open on your VSC and not just the particular file from that directory. I think it'll still throw perm-error's for other things but at least you can run the tests this way.
Unable to Submit Assignment 2
Hi under assignments on the OnQ site there is no where to upload and submit assignment 2 is there somewhere else where we are supposed to submit it?
Pytest
When I run my program, an error shows up on the IDLE Shell: "fileno = sys.stderr.fileno()" and "io.UnsupportedOperation: fileno". It also shows errors happening throughout parts of the pytest package. I've searched online for solutions but have come up short. Does anyone have a clue what this means?
Pytest file access errors etc.
I have been getting messages from several students regarding errors that crop up when using Pytest. It does seem that several IDEs and/or operating systems don't think Pytest should be allowed to do its job. There are a couple of things to try:
1. Try a different IDE, or try running Python from the command line.
2. Make sure you are running your IDE with administrator status.
3. Make sure the directory containing your Python programs is part of your project (or workspace, or domain, or whatever your IDE might call it)
4. Reinstall Pytest.
Final option: submit your assignment without having run the tests. Add a note in your internal documentation stating that you were not able to run your tests due to technical problems. You will not lose grades for this.
Is More Better?
There is no penalty for having lots of tests! However, each test should test a situation that is unique in some significant way.
For example, testing the "list the primes" function individually on every integer from 1 up to 1000 (i.e. writing 1000 tests) is probably not sensible.
Tests with surprising results
If a Pytest test gives an unexpected result, there are two possibilities:
1. There is an error in the unit (i.e. the function) being tested.
2. There is an error in the assertion.
Both of these situations are important. The assertion describes what the tester expects will happen ... maybe the tester misunderstands what the function is supposed to do. Exploring this can help the tester. If the assertion is correct, then the unit is incorrect and will need to be repaired before use (or released with a "known issues" report, which is what happens a lot in real life!). The tester may have thought of a situation that the author of the unit had not considered. This is exactly why we do testing of this kind.
So if you have created a test that gives a result that you did not expect and you are sure that your assertion is correct, you should absolutely include the test. You should add internal documentation explaining why the test should have passed.
It is not necessary to include a test with an assertion that is known to be false, just to get Pytest to print out its failure report. I did this in our demonstration code just so that we could all see what happens when a test fails.
Formatting
As long as your formatting is consistent, you're fine.
Normal Input versus Breaking the Function
One of the maxims of software design is "Never trust the user"
Ideally every function we write should be bullet-proof: calling it with incorrect parameters should be handled gracefully. In the real world this is hardly ever the case. Most well-documented functions will specify the number and type of parameters needed, and if the user deviates from those restrictions then the function is allowed to fail.
But it's perfectly valid to test a function on bad input just to confirm that it does fail as it should. This can be very useful information. I recall a situation where a piece of software was supposed to do one of several different things, based on a parameter value being between (let's say) 1 and 5. A user discovered that it was possible to get the software to accept a parameter value outside that range, and then do something unpredictable. In Python, parameters being untyped is a particular hazard. For example, suppose we are expecting a parameter to be a list, but the user provides a tuple instead. Our function would still be able to iterate through the provided input, but attempting to change it would fail.
Thanks!
I appreciate people using this forum to post questions. It's very useful to be able to post the answers where everyone can see them.