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

documenting how to run integration tests locally #380

Merged
merged 2 commits into from
Apr 7, 2023
Merged
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
66 changes: 66 additions & 0 deletions doc/community/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,28 @@ myst:

# Developer guide

Before continuing, ensure you have a working [development environment.](https://ploomber-contributing.readthedocs.io/en/latest/contributing/setup.html)

Choose a reason for hiding this comment

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

I think that this entire developer-guide.md file should be renamed and moved into a "Testing" -> "JupySQL" section within the contributing portal

I also found it a bit difficult to navigate to the contribution docs from the main website, and would suggest just making the "Developer guide" link pictured below directly go to Contributing since that covers all development instructions for all of your projects

Choose a reason for hiding this comment

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

Screen Shot 2023-04-14 at 1 17 08 PM


+++

## Unit testing

### Running tests

Unit tests are executed on each PR; however, you might need to run them locally.

To run all unit tests:

Choose a reason for hiding this comment

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

i believe that with my added tests on the #319 change, running all unit tests locally started to fail due to a Too many open files error. i was able to bypass it by temporarily increasing my ulimit

ulimit -n 2048

another environment issue specific only to my mac, but having instructions published here in case other users encounter it might be worth writing since 256 is the default for macs.


```sh
pytest --ignore=src/tests/integration
```

To run a specific file:

```sh
pytest src/tests/TEST_FILE_NAME.py
```

Choose a reason for hiding this comment

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

I think it is also helpful to include how to run a specific test in a file likeso:

pytest src/tests/test_magic.py::test_save_with_trailing_semicolon

### Magics (e.g., `%sql`, `%%sql`, etc)

This guide will show you the basics of writing unit tests for JupySQL magics. Magics are commands that begin with `%` (line magics) and `%%` (cell magics).
Expand Down Expand Up @@ -135,3 +153,51 @@ with pytest.raises(ZeroDivisionError) as excinfo:
```{code-cell} ipython3
assert str(excinfo.value) == "division by zero"
```

## Integration tests

Integration tests check compatibility with different databases. They are executed on
each PR; however, you might need to run them locally.

```{note}
Setting up the development environment for running integration tests locally

Choose a reason for hiding this comment

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

Perhaps, consider adding another note here to push developers to rely on the CI to test PRs since integration tests are not yet supported on all OSes

Choose a reason for hiding this comment

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

It might also be helpful to include which OSes are supported

is challenging given the number of dependencies. If you have problems,
[message us on Slack.](https://ploomber.io/community)
```

Ensure you have [Docker Desktop](https://docs.docker.com/desktop/) before continuing.

To install all dependencies:

```sh
# create development environment (you can skip this if you already executed it)
pkgmt setup

# activate environment
conda activate jupysql

# install depdencies
pip install -e '.[integration]'
idomic marked this conversation as resolved.
Show resolved Hide resolved
```

```{tip}
Ensure Docker is running before continuing!
```

To run all integration tests (the tests are pre-configured to start and shut down
the required Docker images):

```sh
pytest src/tests/integration

Choose a reason for hiding this comment

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

When I get to this step, I received the error:

_____________ ERROR collecting src/tests/integration/test_mssql.py _____________
ImportError while importing test module '/Users/alextong/Documents/coding/jupysql/src/tests/integration/test_mssql.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../opt/anaconda3/envs/jupysql/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
src/tests/integration/test_mssql.py:1: in <module>
    import pyodbc
E   ImportError: dlopen(/Users/alextong/opt/anaconda3/envs/jupysql/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so, 2): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
E     Referenced from: /Users/alextong/opt/anaconda3/envs/jupysql/lib/python3.10/site-packages/pyodbc.cpython-310-darwin.so
E     Reason: image not found

Running brew install unixodbc seems to have fixed it as per the instructions on https://pypi.org/project/pyodbc/. I think this step should be added in before line 180 for users on Macs/Unix.

```

```{important}
If you're using **Windows**, the command above might get stuck. Send us a [message on Slack](https://ploomber.io/community) if it happens.
```

To run some of the tests:

```sh
pytest src/tests/integration/test_generic_db_operations.py::test_profile_query
```
Comment on lines +187 to +202

Choose a reason for hiding this comment

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

For consistency with the unit testing section, I would recommend this:

Integration tests are pre-configured to start and shut down
the required Docker images.

To run all integration tests:

```sh
pytest src/tests/integration
```

```{important}
If you're using **Windows**, the command above might get stuck. Send us a [message on Slack](https://ploomber.io/community) if it happens.
```

To run a specific file:

```sh
pytest src/tests/integration/test_generic_db_operations.py
```

To run a specific test:

```sh
pytest src/tests/integration/test_generic_db_operations.py::test_profile_query
```