Skip to content

Add some guides for testing individual PySpark tests at Developer Tools #161

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

Closed
wants to merge 1 commit into from
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
46 changes: 46 additions & 0 deletions developer-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,52 @@ To run individual Java tests, you can use the `-Dtest` flag:
build/mvn test -DwildcardSuites=none -Dtest=org.apache.spark.streaming.JavaAPISuite test
```

<h4>Testing PySpark</h4>

To run individual PySpark tests, you can use `run-tests` script under `python` directory. Test cases are located at `tests` package under each PySpark packages.

To run test cases in a specific module:

```
$ python/run-tests --testnames pyspark.sql.tests.test_arrow
```

To run test cases in a specific class:

```
$ python/run-tests --testnames 'pyspark.sql.tests.test_arrow ArrowTests'
```

To run single test case in a specific class:

```
$ python/run-tests --testnames 'pyspark.sql.tests.test_arrow ArrowTests.test_null_conversion'
```

You can also run doctests in a specific module:

```
$ python/run-tests --testnames pyspark.sql.dataframe
```

Lastly, there is another script called `run-tests-with-coverage` in the same location, which generates coverage report for PySpark tests. It accepts same arguments with `run-tests`.
Copy link
Member

Choose a reason for hiding this comment

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

This is a great improvement. Thanks!
Do we need to mention pip install coverage here since this is an introductory doc? Or, is that too obvious?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be okay - the error message is quite clear (with red colour message haha .. ):

$ ./python/run-tests-with-coverage --python-executables=pypy
...
Coverage is not installed in Python executable 'pypy' but 'COVERAGE_PROCESS_START' environment variable is set, exiting.


```
$ python/run-tests-with-coverage --testnames pyspark.sql.tests.test_arrow --python-executables=python
...
Name Stmts Miss Branch BrPart Cover
-------------------------------------------------------------------
pyspark/__init__.py 42 4 8 2 84%
pyspark/_globals.py 16 3 4 2 75%
...
Generating HTML files for PySpark coverage under /.../spark/python/test_coverage/htmlcov
```

You can check the coverage report visually by HTMLs under `/.../spark/python/test_coverage/htmlcov`.

Please check other available options via `python/run-tests[-with-coverage] --help`.


<h3>ScalaTest Issues</h3>

If the following error occurs when running ScalaTest
Expand Down
40 changes: 40 additions & 0 deletions site/developer-tools.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,46 @@ <h4>Testing with Maven</h4>
<pre><code>build/mvn test -DwildcardSuites=none -Dtest=org.apache.spark.streaming.JavaAPISuite test
</code></pre>

<h4>Testing PySpark</h4>

<p>To run individual PySpark tests, you can use <code>run-tests</code> script under <code>python</code> directory. Test cases are located at <code>tests</code> package under each PySpark packages.</p>

<p>To run test cases in a specific module:</p>

<pre><code>$ python/run-tests --testnames pyspark.sql.tests.test_arrow
</code></pre>

<p>To run test cases in a specific class:</p>

<pre><code>$ python/run-tests --testnames 'pyspark.sql.tests.test_arrow ArrowTests'
</code></pre>

<p>To run single test case in a specific class:</p>

<pre><code>$ python/run-tests --testnames 'pyspark.sql.tests.test_arrow ArrowTests.test_null_conversion'
</code></pre>

<p>You can also run doctests in a specific module:</p>

<pre><code>$ python/run-tests --testnames pyspark.sql.dataframe
</code></pre>

<p>Lastly, there is another script called <code>run-tests-with-coverage</code> in the same location, which generates coverage report for PySpark tests. It accepts same arguments with <code>run-tests</code>.</p>

<pre><code>$ python/run-tests-with-coverage --testnames pyspark.sql.tests.test_arrow --python-executables=python
...
Name Stmts Miss Branch BrPart Cover
-------------------------------------------------------------------
pyspark/__init__.py 42 4 8 2 84%
pyspark/_globals.py 16 3 4 2 75%
...
Generating HTML files for PySpark coverage under /.../spark/python/test_coverage/htmlcov
</code></pre>

<p>You can check the coverage report visually by HTMLs under <code>/.../spark/python/test_coverage/htmlcov</code>.</p>

<p>Please check other available options via <code>python/run-tests[-with-coverage] --help</code>.</p>

<h3>ScalaTest Issues</h3>

<p>If the following error occurs when running ScalaTest</p>
Expand Down