How to run all the unit tests in the edx-platform?

So I installed the edx devstack and wanted to run the unit tests. I found the make e2e-tests command that executes all test cases in the edx-e2e-tests directory. But now I want to execute tests in the edx-platform directory. If I make a similar make command like:

edx-platform-tests: dev.up.lms+studio+firefox+chrome ## Run the edx-platform test cases.
	docker run -t --network=devstack-nutmegmaster_default -v $(DEVSTACK_WORKSPACE)/edx-platform:/openedx/edx-platform --env-file $(DEVSTACK_WORKSPACE)/edx-e2e-tests/devstack_env edxops/e2e env TERM=$(TERM) bash -c 'pytest /openedx/edx-platform'

I get the error:

No module named 'xblock'

If I have installed it correctly shouldn’t xblock be also installed using the requirement file considering it is being used in the project. And if not how do I add it to the project and which installation steps would I have to repeat after changing the requirement.

It seems like you are trying to run the platform tests from the e2e container. You need to run them on the LMS container, and it’s actually simpler than the command you showed.

From your host computer, just run make lms-shell to open a shell in the LMS container, then run pytest (optionally with arguments) to run the tests. See Running LMS and CMS Tests on Devstack (partly outdated though) and Running Python Unit tests in edx-platform.

1 Like

Is there any way to run these tests without invoking the interactive shell, I am building a CI/CD pipeline and the platform does not support an interactive shell.

Of course. pytest does not depend on an interactive shell.

The details of how to achieve this will depend on what sort of CI/CD setup you’re using. You can try to see how it’s done using GitHub Actions on the edx-platform repo itself, because the tests there run for every PR and every commit to master.