-
I what to call pytest.main this way:
I have debugged pytest and search online and until now I know the -c flag should be used to use a pytest.ini outside the test folder but for my application it doesnt work as it should, or Im using it the wrong way? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
So I have been debugging for days, and made one small finding until now: on _pytest\main.py on line 772, When the pytest.ini is not inside the test folder and the -c flag is used, for each .py that I pass on my command to pytest.main() a module is created, but is not given a name so only the first file tests get collected and the tests from the second file since the second module/file also has no name it is considered as already loaded so is not collected. When the pytest.ini is inside the tests folder then for each file that I pass to pytest.main() a module is created and given the name of the .py file, so since the second file/command has different name than the first, it does get loaded/collected by pytest since its considered as not loaded, the oposite of what happens when the module have no name and since the first no name module is loaded the second is considered to be the same so it doesnt get loaded. |
Beta Was this translation helpful? Give feedback.
-
The solution was to pass --rootdir=path\tests in the arguments to the pytest.main() since the modules/nodes are named based on the relative path from rootdir and the path to the python file where the tests are, in this case tests\testfile1 or testfile2. What I was doing before was that the rootdir was completely different to the path to the testfile1.py or testfile2.py, so the relative path did not work(constuctor FSCollector of node.py in pytest code), so only the first one was loaded unnamed(collect() function in main.py), and since the second module was also not named it was considered to be the same as the first, and the tests in testfile2.py where not loaded. |
Beta Was this translation helpful? Give feedback.
The solution was to pass --rootdir=path\tests in the arguments to the pytest.main() since the modules/nodes are named based on the relative path from rootdir and the path to the python file where the tests are, in this case tests\testfile1 or testfile2.
What I was doing before was that the rootdir was completely different to the path to the testfile1.py or testfile2.py, so the relative path did not work(constuctor FSCollector of node.py in pytest code), so only the first one was loaded unnamed(collect() function in main.py), and since the second module was also not named it was considered to be the same as the first, and the tests in testfile2.py where not loaded.