Open johanvergeer opened 4 years ago
Inserting
if __name__ == '__main__':
import sys, pytest
pytest.main(sys.argv)
to a test script (say, test_mod.py) allows running scalene on the pytest compatible test functions. For instance:
scalene --profile-all test_mod.py -sv -x
In general, to invoke scalene, the following pattern appears to apply:
scalene <scalene options> /path/to/test_mod.py <pytest options>
I found this way to run a single test case: scalene -m test_case_file -k TestCaseClass.test_case_function
thanks to ChatGPT :sweat_smile: not sure if this is documented anywhere.
Is your feature request related to a problem? Please describe. We already have a big test suite that could be used directly to profile specific functionality. I have not found a way to run Scalene with Pytest.
Describe the solution you'd like It would be really cool when a Pytest plugin could be created that allows us to run a (set of) tests with Scalene running in the background. I could come up with two solutions:
The first solution is to run pytest trough Scalene
The second solution is to add a flag to pytest that runs Scalene.
The latter would have my preference, since that would allow us to have more fine-grained tests and it would allow us to add test configurations in an IDE (like PyCharm).
Describe alternatives you've considered
At this moment, the only alternative that I could come up with is to create a separate script that runs the code just for profiling.