pytest errors
Closed this issue · 3 comments
While attempting to add tests for #23, I hit a couple of pytest errors:
1: test_inspector
is hardcoded to look for D:\pycharm_projects
in the exception object. As I am running in a different directory, this test fails.
2: Many different tests use cwd
when they should use e.g. os.path.realpath(__file__)
instead.
3: Even though the main code works with either pyyaml
or ruamel.yaml
, test_multiprocessing
is hardcoded to use ruamel.yaml
- and Murphy's law meant that of course I had only pyyaml
installed.
All easily fixed - I'll throw up a PR in a bit. Don't know where this project falls on the sliding scale between 'a billion tiny PRs' and 'one huge PR'.
1 is fixed by #25
Thanks for your finding.
1: test_inspector is hardcoded to look for D:\pycharm_projects in the exception object. As I am running in a different directory, this test fails.
Sorry, I was in a hurry at that time so I left it as is. Should have used regex instead.
2: Many different tests use cwd when they should use e.g. os.path.realpath(file) instead.
Pytest is invoked inside that tests
directory, so Path.cwd()
is fine.
The longer version if needed, will be Path(__file__).parent
.
The reason for cwd
is the tests
directory is that some tests need to call the external py files, which are in the same directory.
So using the tests
directory as cwd
made writing tests easier.
If there is a reason for using os.path.realpath(__file__)
, please let me know.
3: Even though the main code works with either pyyaml or ruamel.yaml, test_multiprocessing is hardcoded to use ruamel.yaml - and Murphy's law meant that of course I had only pyyaml installed.
Yeah, I should have rewritten that better. But since the ruamel.yaml
was supported later, I just used it over pyyaml
.
Pytest is invoked inside that tests directory, so Path.cwd() is fine.
It works if you invoke pytest inside the tests directory, yes.
pytest 'normally' also works if you invoke it in the project base directory. Notably, this is the default behavior for pytest in vscodium, which breaks test discovery.
(see also microsoft/vscode-python#8678 )