Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure edx-platform tests can run without fiddling with environment variables #648

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-nightly.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Note: Breaking changes between versions are indicated by "💥".

- [Improvement] edx-platform unit tests can now be run without needing to manually set environment variables.
- [Improvement] For Tutor Nightly (and only Nightly), official plugins are now installed from their nightly branches on GitHub instead of a version range on PyPI. This will allow Nightly users to install all official plugins by running ``pip install -e ".[full]"``.
- [Bugfix] Remove edX references from bulk emails ([issue](https://github.com/openedx/build-test-release-wg/issues/100)).
- [Bugfix] Update ``celery`` invocations for lms-worker and cms-worker to be compatible with Celery 5 CLI.
Expand Down
34 changes: 19 additions & 15 deletions docs/dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ To collect assets, you can use the ``openedx-assets`` command that ships with Tu
tutor dev run lms openedx-assets build --env=dev


.. _specialized for developer usage:
.. _specialized for developer usage:

Rebuilding the openedx-dev image
--------------------------------
Expand Down Expand Up @@ -255,26 +255,30 @@ You should then run the development server as usual, with ``start``. Every chang
Running edx-platform unit tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's possible to run the full set of unit tests that ship with `edx-platform <https://github.com/openedx/edx-platform/>`__. To do so, run a shell in the LMS development container::
It's possible to run the full set of unit tests that ship with `edx-platform <https://github.com/openedx/edx-platform/>`__. Some tests are intended to be run in an LMS context, some are intended for the CMS context, and some can be run in both. To run tests for the LMS, start a shell in the LMS container::

tutor dev run lms bash

Then, run unit tests with ``pytest`` commands::
Then, simply `invoke pytest <https://docs.pytest.org/en/latest/how-to/usage.html>`_. For example::

# Run tests on common apps
unset DJANGO_SETTINGS_MODULE
unset SERVICE_VARIANT
export EDXAPP_TEST_MONGO_HOST=mongodb
pytest common
pytest openedx
pytest lms # Run tests for the entire LMS source tree.
pytest lms/djangoapps/ccx # Run tests in a single LMS app.
pytest lms/djangoapps/ccx -k '_override or _structure' # Run tests in a single LMS app with names matching substring(s).
pytest openedx common # Run tests for both shared source trees.
pytest openedx/core/djangoapps/content/course_overviews # Run tests for a single shared app.
# ... etc.

# Run tests on LMS
export DJANGO_SETTINGS_MODULE=lms.envs.tutor.test
pytest lms
To run CMS tests, start a shell in the CMS container::

# Run tests on CMS
export DJANGO_SETTINGS_MODULE=cms.envs.tutor.test
pytest cms
tutor dev run cms bash

As before, simply invoke pytest. Tests under the cms/ source tree will automatically use CMS settings. For tests under the shared source trees, you will need to tell pytest to look in the cms/ directory for configuration by providing ``--rootdir`` option::

pytest cms # Run tests for the entire CMS source tree.
pytest cms/djangoapps/coursegraph # Run tests in a single CMS app.
pytest --rootdir=cms openedx common # Run tests for both shared source trees.
pytest --rootdir=cms openedx/core/djangoapps/content/course_overviews # Run tests for a single shared app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contradicts the instruction from line 268. I'm confused: do we need to specify the rootdir when running shared app tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@regisb Right, sorry, it's a little convoluted.

By default, ALL tests will use lms.envs.test (because of edx-platform's setup.cfg) EXCEPT the tests under cms/, which will use cms.envs.test (because of edx-platform's cms/pytest.ini).

This is generally reasonable, except that sometimes folks will want to run tests for the "shared" directories (openedx/ and common/) in a CMS context. The easiest way to make this happen is to tell pytest to look at the cms/ directory for a pytest.ini, hence --rootdir=cms.

As I think more about this, I really wish we could just have the behavior of:

  • tests in lms/ always use lms.envs.test,
  • tests in cms/ always use cms.envs.test,
  • tests in shared directories use lms.envs.test when in the LMS container, and use cms.envs.test when in the CMS container.

Orchestrating that will take some hair-pulling. For the conference, I think we'll just have to accept the status quo. The current instructions, while a little annoying, certainly work for the vast majority of edx-platform tests :)

# ... etc.

.. note::
Getting all edx-platform unit tests to pass on Tutor is currently a work-in-progress. Some unit tests are still failing. If you manage to fix some of these, please report your findings in the `Tutor forums <https://discuss.overhang.io>`__.
2 changes: 2 additions & 0 deletions tutor/templates/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
command: ./manage.py lms runserver 0.0.0.0:8000
environment:
DJANGO_SETTINGS_MODULE: lms.envs.tutor.development
EDXAPP_TEST_MONGO_HOST: mongodb
ports:
- "8000:8000"
networks:
Expand All @@ -44,6 +45,7 @@ services:
command: ./manage.py cms runserver 0.0.0.0:8000
environment:
DJANGO_SETTINGS_MODULE: lms.envs.tutor.development
EDXAPP_TEST_MONGO_HOST: mongodb
ports:
- "8001:8000"

Expand Down